Reputation: 1012
I am writing cucumber feature and I need to fill value in text field within iframe. I have tried with
find("#user_email").set "malicious_value"
but couldn't get success. I have selenium webdriver.
Upvotes: 4
Views: 2393
Reputation: 5082
If you want to do any thing inside the frame
. First you have to go inside the frame.
Code to enter the frame:
//Assume driver is initiated properly some where.
driver.switchTo.frame(FrameName);
(Or)
driver.switchTo.frame(FrameIndexValue);
(Or)
WebElement element = driver.findElement(By.id(LocatorValue));
driver.switchTo.frame(element);
After finishing your action inside the frame. You have to come out to frame by using
code to leave the frame:
driver.switchTo.defaultContent();
If you are dealing with the iframe
then the defaultContent() will take you to the main page above all the iframes, but if you deal with the frame
this method will take you to the first frame of the page.
For more information on frame handling.
Upvotes: 1
Reputation: 174
This is ruby code with selenium to switch in iframe. you can do it by:
#Move into iframe
page.driver.browser.switch_to.frame "name or id of frame"
#Move to default content or outsite frame
page.driver.browser.switch_to.default_content
Upvotes: 3