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();
}
}
答案 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);