繁体   English   中英

Selenium - 我无法在谷歌的“继续之前”对话框中单击按钮

[英]Selenium - I can't click button in dialog “Before you continue” in google

我有一个问题,点击谷歌对话框中的按钮。 这是我的代码:

@BeforeEach
public void startDriver() throws InterruptedException {
    // Start Chrome browser
    System.setProperty("webdriver.chrome.driver", "C:\\gecko\\chrome\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.get("https://www.google.pl/?gws_rd=ssl");
}

@Test
@DisplayName("Test strony google")
public void testGoogle() throws InterruptedException, IOException {
    System.out.println("Rozpoczecie testu strony google");
    ModelStatistic modelStatistic = new ModelStatistic();
    System.out.println(modelStatistic.getTimestamp());
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    Thread.sleep(4000);
    WebElement agree = driver.findElement(By.id("introAgreeButton"));
    agree.click();
    Thread.sleep(3000);
    WebElement name = driver.findElement(By.cssSelector("input[name='q']"));
    name.sendKeys("Kamil Surma");
}

Selenium Cant's see Webelement 同意。

我同意

添加这个: driver.switchTo().frame(0);

在此之前: WebElement agree = driver.findElement(By.id("introAgreeButton"));

该按钮在 iframe 中,驱动程序找不到它。

您还可以添加: driver.wait(until.ableToSwitchToFrame(0)); 而是Thread.sleep(4000);driver.switchTo().frame(0);

它会自动切换

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM