I know this question has been asked several times, but I haven't been able to figure out my issue. I'm trying to select the 'fraHeader' frame but all I can get is 'Unable to locate element' errors. I'm using Webdriver with Java
Things I've tried:
using driver.findElement to find the frame, then driver.switchTo to switch to it - that doesn't work. I consistently get 'Unable to locate element'.
I have tried using xpath, id and name to locate the frames, but none work.
Here is my website code:
<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>
•
I'm new to Selenium and appreciate any help.
Perhaps you need to use WebDriverWait to wait for the frame to be visible. What you tried was implicit wait, explicit wait might be a worth try.
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement iframe = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("masterFrameset"));
driver.switchTo().frame(iframe);
or
driver.switchTo().frame("masterFrameset");
or if the iframe is first one?
driver.switchTo().frame(0);
In addition to what @nilesh has suggested, you can also use the below code to wait for frame to appear and switch to it:
//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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With