selenium.selectFrame("navigator");
selenium.click("link=mylink");
selenium.selectFrame("relative=up");
selenium.selectFrame("content");
selenium.type("myinputfield", "7");
Now when I try to run this code I get error at relative=up.So I google and find that this is not the way to write webdriver code.I rewrote the entire code in the webdriver style coding .So now I have this code.
driver.switchTo().frame("navigator");
WebElement my_nav_link = driver.findElement(By.partialLinkText("MyLinkText"));
my_nav_link.click();
driver.switchTo().frame("content");
WebElement myinputfieldelem= driver.findElement(By.id("myinputfield"));
myinputfieldelem.sendKeys("7");
Now when I try again , it errors out at frame not found for content .
So I try to debug a bit and I add the below code just before switch to frame to see all the frames present.
List<WebElement> frameset=driver.findElements(By.tagName("frame"));
if(frameset.size()>0)
{
for (WebElement framename :frameset)
{
System.out.println("frame id:" + framename.getAttribute("name"));
}
}
There are no frames ,so that means I am now in navigator frame and I have to go one level up to find the frame content.
So I tried
driver.switchTo().frame("relative=up");
This also failed.Now I am clueless and and could not figure out what to do.After some googling i found out another option which saved me and the final code which works is as below.
driver.switchTo().frame("navigator");
WebElement my_nav_link = driver.findElement(By.partialLinkText("MyLinkText"));
my_nav_link.click();
driver.switchTo().defaultContent();
driver.switchTo().frame("content");
WebElement myinputfieldelem= driver.findElement(By.id("myinputfield"));
myinputfieldelem.sendKeys("7");
So the outcome is you have to use switchTo().defaultContent() to be able to come out of a frame and go to a sibling frame.
Hi Evelin,
ReplyI am unable to execute switchTo to call another url inside of my widget farme. Here is my code driver.switchTo().frame("../pack/start?lang=en_US&owf=true"); but it is not working, it says, "No frame found." Do you have any other solution for me? please help.
Hi Kobir,
I am not sure If I got your question correctly.Here I am explaining about switching between frames within a webpage.The argument for switchTo().frame() should be the name of a frame within the webpage.
If you want to open a new url, you can try out open(url) referred here -http://release.seleniumhq.org/selenium-core/0.8.0/reference.html.
I have not used it myself.Try it and see.
Hi Evelin, If I have two web URL and if currently my control is in First Webpage then how to go the second webpage and search for the target frame. Any help will be appreciate. Thanks in advance. :)
Regards,
Mukesh
Hi,
Please send some docs..
I was having issues with going from the Selenium IDE commands
ReplyselectFrame relative=up
selectFrame main
to the webDriver equivalent.
Thank you very much for posting this, the commands:
driver.switchTo().defaultContent();
driver.switchTo().frame("main");
were exactly what I needed in order to continue through the script.
the commands:
driver.switchTo().defaultContent();
driver.switchTo().frame("main");
were exactly what I needed in order to continue through the script.
Great !
Thanks a lot !!
It works also in case of "iframe" and with the id as parameter (when no name available).
S.
thanks for the post.. this is really helpful..
ReplyMerry Christmas Evelin
ReplyExcellent piece of information..
ReplyHi Evelin,
ReplyI am working on iframe which has one html tag inside another html tag. After I switched to frame(FrameID) I can access all the object presented in the first html, but i cannot access the object presented in second html. Any Help??
- Bala
Hi All,
ReplyI am working on iframe which has one html tag inside another html tag. After I switched to frame(FrameID) I can access all the object presented in the first html, but i cannot access the object presented in second html. Any Help??
- Bala
i have an issue that my frame that changing dynamically and do not have any name
Replyi m unable to switch in that frame any help buddies i tried alot but got nothing ............
hi,
Replywe can use driver.switchTo().frame(0); to switch in to that frame.If name and id are not present for frame.
|html>
Reply|frameset>
|frameset>
|frame>
|html>
|body>
|input id='abc'>
|/body>
|/html>
|/frame>
|/frameset>
|/frameset>
|/html>
How to find the Web Element "Input"?
This saved my day, thanks a lot.
ReplyDoes anyone here has contact to the Selenium guys, so they put this remark about the defaultContent() method on their website?
Hi Evelin,
ReplyI am also working with multiple frames. In my situation, on clicking on a link in a frame, content of another frame changes. I need to verify if the other frame is loading or not. How to do that? I am able to switch between the frames.
Great post. It helped me.
ReplyThanks.it helped me :)
ReplyWOW Thanks a lot!!!! it really helped me a loooooooot :)
ReplyThank you very much, so helpful information!!
ReplyThanks, it helped a lot
ReplySolved my problem.. Thanks a tone..!!! :)
Replyworked for me. Thanks.
ReplyHi Evelin,
ReplyI have been searching for this from past 1 day... Thanks a ton!!!
|html>
Reply|frameset> frameset have only "title" no "id" and no "name"
|frame> frame have only "title" no "id" and no "name"
|html>
|body>
|input class='abc'>
|/body>
|/html>
|/frame>
|/frameset>
|/html>
|html>
Reply|frameset> frameset have only "title" no "id" and no "name"
|frame> frame have only "title" no "id" and no "name"
|html>
|body>
|input class='abc'>
|/body>
|/html>
|/frame>
|/frameset>
|/html>
please tell me how to access input