How to fill value in textbox using iframe

I am writing a cucumber function and I need to fill a value in a textbox inside an iframe. I tried with

find("#user_email").set "malicious_value"

      

but failed to succeed. I have selenium webdriver.

+3


source to share


2 answers


This is ruby ​​code with selenium to switch to iframe. You can do it:



#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

      

+3


source


If you want to do something inside frame

. First you need 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 completing the action inside the frame. You have to get out of the box using



to leave a border:

  driver.switchTo.defaultContent();

      

If you are dealing with iframe

, then defaultContent () will take you to the main page above all frames, but if you are dealing with frame

, this method will take you to the first frame of the page.

More information about frmae processing .

+1


source







All Articles