我知道这个问题已被问过几次,但我一直无法弄清楚我的问题。我正在尝试选择'fraHeader'框架,但我能得到的是'无法找到元素'错误。我正在使用带Java的Webdriver
我尝试过的事情:
使用driver.findElement查找帧,然后使用driver.switchTo切换到它 - 这不起作用。我一直得到'无法找到元素'。
我尝试使用xpath,id和name来定位框架,但都没有工作。
这是我的网站代码:
<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的新手并感谢您的帮助。
答案 0 :(得分:2)
也许您需要使用WebDriverWait等待框架可见。您尝试的是隐式等待,显式等待可能值得尝试。
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement iframe = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("masterFrameset"));
driver.switchTo().frame(iframe);
或
driver.switchTo().frame("masterFrameset");
或iframe是第一个?
driver.switchTo().frame(0);
答案 1 :(得分:2)
除了@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"));