![](/img/trans.png)
[英]Error :Cannot instantiate the type Select in selenium webdriver
[英]Cannot Select Frames in Selenium Webdriver
我知道這個問題已被問過好幾次,但我一直無法弄清楚我的問題。 我正在嘗試選擇'fraHeader'框架,但我能得到的是'無法找到元素'錯誤。 我正在使用Webdriver和Java
我試過的事情:
使用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的新手,感謝任何幫助。
也許你需要使用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);
除了@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"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.