Selenium_无法在Gaana网页上单击“与Google继续”链接

时间:2020-02-13 15:11:21

标签: java selenium selenium-webdriver

Screenshot of webpage 已经尝试使用定位器By.ID并切换到警报,切换到Windows ..但没有运气 请帮忙

public class Gaana {

        public static void main(String[] args) throws InterruptedException {
            System.setProperty("webdriver.chrome.driver", "C:\\Users\\Music\\Selenium\\chromedriver.exe");  
            ChromeOptions ops = new ChromeOptions();
            ops.addArguments("--disable-notifications");
            WebDriver driver = new ChromeDriver(ops);
            driver.get("https://gaana.com/");
            Thread.sleep(3000);
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            WebElement googleLgn = driver.findElement(By.xpath("//*[contains(text(),'Continue with Google')]"));        
            googleLgn.click();
        }               

    }

1 个答案:

答案 0 :(得分:0)

有2个登录按钮,它们具有相同的Id和相同的class名称。尝试在xpath下面找到正确的按钮。

WebDriverWait wait1 = new WebDriverWait(driver, 50);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("(//a[@id='google-login'])[1]")));
element1.click();

OR

尝试使用JS

WebElement ele = driver.findElement(By.xpath("(//a[@id='google-login'])[1]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);