Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Select Frames in Selenium Webdriver

Tags:

java

selenium

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:

  1. 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'.

  2. I have tried using xpath, id and name to locate the frames, but none work.

  3. recording the actions using Selenium IDE and exporting to Java - that gives me: // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | fraHeader | ]]
  4. inserting mydriver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); incase the code is running too fast. That also does not help.

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>
&#0149;

I'm new to Selenium and appreciate any help.

like image 835
user3977009x Avatar asked Aug 04 '26 19:08

user3977009x


2 Answers

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);
like image 93
nilesh Avatar answered Aug 06 '26 10:08

nilesh


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"));
like image 42
Subh Avatar answered Aug 06 '26 09:08

Subh