簡體   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