I have web page which has two frames -navigator and content.I have to click on a link in the navigator and the content of the frame 'content' changes.Now I have to input some value in the content frame.I use IDE to record and generate code in the junit4 webdriver format.
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,
ReplyDeleteI 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,
DeleteI 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. :)
DeleteRegards,
Mukesh
Hi,
DeletePlease send some docs..
I was having issues with going from the Selenium IDE commands
ReplyDeleteselectFrame 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:
Deletedriver.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..
ReplyDeleteMerry Christmas Evelin
ReplyDeleteExcellent piece of information..
ReplyDeleteHi Evelin,
ReplyDeleteI 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,
ReplyDeleteI 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
ReplyDeletei m unable to switch in that frame any help buddies i tried alot but got nothing ............
hi,
ReplyDeletewe can use driver.switchTo().frame(0); to switch in to that frame.If name and id are not present for frame.
|html>
ReplyDelete|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.
ReplyDeleteDoes anyone here has contact to the Selenium guys, so they put this remark about the defaultContent() method on their website?
Hi Evelin,
ReplyDeleteI 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.
ReplyDeleteThanks.it helped me :)
ReplyDeleteWOW Thanks a lot!!!! it really helped me a loooooooot :)
ReplyDeleteThank you very much, so helpful information!!
ReplyDeleteThanks, it helped a lot
ReplyDeleteSolved my problem.. Thanks a tone..!!! :)
ReplyDeleteworked for me. Thanks.
ReplyDeleteHi Evelin,
ReplyDeleteI have been searching for this from past 1 day... Thanks a ton!!!
|html>
ReplyDelete|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>
ReplyDelete|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
name = output.driver.find_element_by_class_name('yui-panel-container shadow yui-overlay-hidden')
ReplyDeleteAttributeError: 'unicode' object has no attribute 'driver'
I need any solution