[英]Selenium - I can't click button in dialog “Before you continue” in google
I have a problem , click button in dialog forms in google.我有一个问题,点击谷歌对话框中的按钮。 This is my code :这是我的代码:
@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 agree. Selenium Cant's see Webelement 同意。
I agree 我同意Add this: driver.switchTo().frame(0);
添加这个: driver.switchTo().frame(0);
before that: WebElement agree = driver.findElement(By.id("introAgreeButton"));
在此之前: WebElement agree = driver.findElement(By.id("introAgreeButton"));
The button is in iframe and driver can't find it.该按钮在 iframe 中,驱动程序找不到它。
You can also add this: driver.wait(until.ableToSwitchToFrame(0));
您还可以添加: driver.wait(until.ableToSwitchToFrame(0));
instead Thread.sleep(4000);driver.switchTo().frame(0);
而是Thread.sleep(4000);driver.switchTo().frame(0);
It will switch automatically它会自动切换
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.