Java 无法在Selenium Webdriver中选择帧
我知道这个问题已经被问过好几次了,但我一直无法解决我的问题。我正在尝试选择“fraHeader”帧,但我只能得到“无法定位元素”错误。我将Webdriver与Java一起使用 我尝试过的事情:Java 无法在Selenium Webdriver中选择帧,java,selenium,Java,Selenium,我知道这个问题已经被问过好几次了,但我一直无法解决我的问题。我正在尝试选择“fraHeader”帧,但我只能得到“无法定位元素”错误。我将Webdriver与Java一起使用 我尝试过的事情: 使用driver.findElement查找帧,然后使用driver.switchTo切换到帧-这不起作用。我总是得到“无法定位元素” 我曾尝试使用xpath、id和名称来定位帧,但都不起作用 使用Selenium IDE记录操作并导出到Java-这给了我://ERROR:catched exceptio
<meta http-equiv="expires" content="-1">
<meta http-equiv= "pragma" CONTENT="no-cache">
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
<meta name="robots" content="noindex,nofollow">
<link rel="P3Pv1" href="/w3c/p3p.xml">
<script type="text/javascript" src="/scripts/frameset.js"></script>
</head>
<frameset id='masterFrameset' rows='130,*,25' border='0' framespacing='0' frameborder='no' onload=''>
<frame name='fraHeader' noresize scrolling='no' marginwidth='0' marginheight='0' frameborder='no' src='/header-default.jsp'>
<frame name='fraBody' noresize scrolling='auto' marginwidth='0' marginheight='0' frameborder='no' src='/control/store/login'>
<frame name='fraFooter' noresize scrolling='no' marginwidth='0' marginheight='0' frameborder='no' src='/footer-default.jsp'>
</frameset>
</html>
•
我是Selenium新手,非常感谢您的帮助。也许您需要使用WebDriverWait来等待框架显示。您尝试的是隐式等待,显式等待可能值得一试
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement iframe = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("masterFrameset"));
driver.switchTo().frame(iframe);
或
或者如果iframe是第一个
driver.switchTo().frame(0);
除了@nilesh的建议之外,您还可以使用下面的代码等待帧出现并切换到它:
//Wait for 30 seconds for the frame with name "fraHeader" to appear and then switch to it.
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("fraHeader"));
这两个建议对我都不起作用。两者都会导致超时错误。driver.findElement(按.tagName(“fraHeader”);是成功的,但我无法切换到该元素。是否可以将driver.switchTo()与框架以外的任何其他方法一起使用?切换到框架后是否尝试访问任何其他元素,因为它显示错误?我的最终目标是:driver.findelelement(By.tagName(“fraHeader”);然后是driver.switchTo().frame(“fraHeader”);我可以找到元素,但问题是我无法切换到帧。因此,为了回答您的问题,我在之后不会访问任何其他元素,因为我无法通过switchTo命令;driver.switchTo().defaultContent();driver.switchTo().frame(“fraHeader”);谢谢大家的帮助!干得好。。你自己想出来的……)
//Wait for 30 seconds for the frame with name "fraHeader" to appear and then switch to it.
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("fraHeader"));