Selenium Web Driver (with Java) can not locate the iframe - Stack Overflow

I am following a tutorial that navigates to a site: demo.opencart and then prints the title. However, t

I am following a tutorial that navigates to a site: demo.opencart and then prints the title. However, the website now has a human verification page before taking the user to the landing page. However, selenium can not locate the iframe. I tried using the tag name - iframe, and also other locators such as css selector and xpath and nothing works.

Exception in thread "main" .openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //[@id="cf-chl-widget-0uz88"] (tried for 20 second(s) with 500 milliseconds interval) at .openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:84) at .openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228) at sdet21.FirstTestCase.main(FirstTestCase.java:32) Caused by: .openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//[@id="cf-chl-widget-0uz88"]"} (Session info: chrome=134.0.6998.36)

Here is my code:

    WebDriver driver = new ChromeDriver();
    driver.navigate().to("/");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    WebDriverWait waitForIframe = new WebDriverWait(driver, Duration.ofSeconds(20));
    WebElement iframe = waitForIframe.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"cf-chl-widget-0uz88\"]")));
    driver.switchTo().frame(iframe);
    
    //List<WebElement> iframes = driver.findElements(By.tagName("iframe"));
    //System.out.println("Number of iframes: " + iframes.size());
    //driver.switchTo().frame(iframes.get(0));
    
    //WebElement checkbox = driver.findElement(By.xpath("//*[@id=\"uATa8\"]/div/label/input"));
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement checkbox = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"uATa8\"]/div/label/input")));
    checkbox.click();
    
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String pageTitleString = driver.getTitle();
    System.out.println("Page Title: " + pageTitleString);
    driver.close();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744890282a4599369.html

相关推荐

  • Selenium Web Driver (with Java) can not locate the iframe - Stack Overflow

    I am following a tutorial that navigates to a site: demo.opencart and then prints the title. However, t

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信