Selenium Java:无法访问 iframe 中的元素

问题描述 投票:0回答:1

我需要访问网页上 iframe id =“myFrame”内的元素https://cloud.google.com/products/calculator-legacy

我已经尝试过这个解决方案,但它不起作用:

By frameXpath = By.xpath("//iframe[@id='myFrame']");
new WebDriverWait(driver, Duration.ofSeconds(20))
               .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameXpath));

WebElement frame = driver.findElement(frameXpath);
driver.switchTo().frame(frame);

我也尝试过这个解决方案,但它也不起作用:

new WebDriverWait(driver, Duration.ofSeconds(20))
                .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(
        By.xpath("//devsite-iframe/iframe")));

By frameXpath = By.xpath("//iframe[@id='myFrame']");

new WebDriverWait(driver, Duration.ofSeconds(20))
                .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameXpath));

driver.switchTo().frame(driver.findElement(frameXpath));

我有一个例外:“NoSuchElementException:无法定位元素://iframe[@id='myFrame']”

有没有办法访问元素来设置估计条件? 谢谢!

java selenium-webdriver iframe
1个回答
0
投票

问题是您错过了“myFrame”IFRAME 上方的 IFRAME。

© www.soinside.com 2019 - 2024. All rights reserved.