Java Selenium processing elements in an IFRAME
Sometimes when we locate elements, we find that we cannot locate them. You need to check to see if the element you're targeting is in the IFRAME.
Reading Table of Contents
What is an IFRAME?
An IFRAME is HTML, used for Web page nesting. A Web page can be nested into another page and can be nested in many layers.
Selenium provides a way to enter the IFRAME
Enter the IFRAME Dr.switchto () with ID called Framea
(). FRAME ("Framea");
Return to the main window
Dr.switchto (). Defaultcontent ();
Main.html
Frame.html
Selenium code
public static void Testiframe (Webdriver driver)
{
driver.get ("E:\\stashfolder\\huoli_28@hotmail.com\\stash \\Tank-MoneyProject\\ Pudong Software Park training center \ My textbook \\Selenium webdriver\\frame\\main.html ");
In the main window
driver.findelement (by.id ("Maininput")). SendKeys ("main input");
At this time did not enter the IFRAME, the following statement will error
//driver.findelement (by.id ("Iframeinput")). SendKeys ("iframe input");
Driver.switchto (). FRAME ("Framea");
Driver.findelement (By.id ("Iframeinput")). SendKeys ("iframe input");
There is no main window, the following statement will error
//driver.findelement (by.id ("Maininput")). SendKeys ("main input");
Return to the main window
Driver.switchto (). Defaultcontent ();
Driver.findelement (By.id ("Maininput")). SendKeys ("main input");
}
The above is the Java selenium processing the elements of an IFRAME example, follow-up to continue to collate relevant information, thank you for your support of this site!