how to navigate between frames

810 views
Skip to first unread message

mallik swamy

unread,
Jun 4, 2012, 6:55:12 AM6/4/12
to webdriver
Hi all,
I am using Java with web driver. I have case like i have two sections
in my GUI page.The first half is to select the option we want and the
second half to give he details in the form like msisdn, uploading an
image etc.And i have recorded the test case using selenium ide.I have
got some values like

select Frame relative=up

select Frame middle Frame

so when i am using these to identify my code is not able to identify
them.

But the same with value

select Frame main Frame is working fine and i am able to navigate.But
the second case is not able to recognise it.so how can i resolve it.

driver.get("http://172.19.1.226:9000/msdp/cpuser/indexAction.do");


driver.findElement(By.name("username")).sendKeys(username);


driver.findElement(By.name("password")).sendKeys(password);

driver.findElement(By.className("ButtNewPage")).submit();
driver.switchTo().frame("mainFrame");
driver.findElement(By.xpath("/html/body/form/table/tbody/
tr[2]/td/table/tbody/tr/td/ul/li/span")).click();
driver.findElement(By.xpath("/html/body/form/table/tbody/
tr[2]/td/table/tbody/tr/td/ul/li/ul/li[2]/a")).click();
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);

And if i am using as
driver.switchTo().frame("relative=up");
driver.switchTo().frame("middleFrame");

These are throwing errors as unable to find the element.

So please help in resolving this.

thanks in advance

mallik



jyo rani

unread,
Jun 5, 2012, 5:48:23 PM6/5/12
to webd...@googlegroups.com
Try this

  driver.switchTo().frame("relative=up");
driver.switchTo().defaultContent();
         driver.switchTo().frame("middleFrame"); 


mallik



--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


mukesh rawat

unread,
Jun 6, 2012, 1:43:25 AM6/6/12
to webd...@googlegroups.com
In WebDriver,  frame switching is done in these ways:

driver.switchTo().frame(framename);
 driver.switchTo().frame(index_value); //index_value starts from 0
driver.switchTo().defaultContent();


code u mentioning is used in Selenium RC.

Thanks,
Mukesh

darrell

unread,
Jun 6, 2012, 8:54:34 AM6/6/12
to webdriver
Have a look at http://darrellgrainger.blogspot.ca/2012/04/frames-and-webdriver.html.
It gives a little information about my experience with frames.

In a nutshell, a frame is like switching to a different window. When
you are on window #1 or frame #1 then you cannot findElement on any
elements in window #2 or frame #2.

To switch to a frame you need either the id attribute, the name
attribute, an index or the WebElement which is the FRAME tag. So if I
have:

<html>
<head><title>Frame example</title></head>
<body>
<iframe id="myFrame" name="frameName" src="frame3.html"></iframe>
</body>
</html>

If the current context is this page I can do the following to interact
with elements in the frame:

driver.switchTo().frame("myFrame"); // find frame by ID
or
driver.switchTo().frame("frameName"); // find frame by NAME
or
WebElement frameElement = driver.findElement(By.xpath("//
iframe[@src='frame3.html']"));
driver.switchTo().frame(frameElement);

Any thing which works for findElement could be used. I picked xpath
but I could have easily used some other By identifier.

Once you switch to the frame, if you want to interact with things on
the main window, you have to switch back to the main window:

driver.switchTo().default();

Darrell
Reply all
Reply to author
Forward
0 new messages