谁能告诉我如何识别并切换到没有标题和 ID 的 iframe。 iframe 的一部分(我有两个具有相同属性的 iframe):
<iframe style="width: 1335px; height: 223px;" src="javascript:true;" frameborder="0">
<html>
#document
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
</html>
</html>
</iframe>
如何使用 Java 解决 Selenium WebDriver 中的这个问题? 将不胜感激任何帮助。
最佳答案
您可以尝试以下解决方案。
如有必要,请在从 iframe 访问网络元素之前尝试切换到默认内容。因此,在检测 iframe 的代码之前添加以下代码。
driver.switchTo().defaultContent();
WebDriverWait wait = new WebDriverWait(driver,20);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe")));
关于java - 当框架没有id和标题时,如何识别并切换到selenium webdriver中的框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32581667/