Recently in the use of Webdriver Crawler, encountered the site of the IFRAME, processing a long time no solution, and later found that the original Webdriver processing methods, ashamed.
1, the IFRAME has the ID or name of the case
Enter the id= "FRAME1" frame and locate the id= "Div1" div and the input box id= "INPUT1".
Dr.switchto (). FRAME ("frame1");
Dr.findelement (By.id ("Div1"));
Dr.findelement (By.id ("INPUT1"))
2, if an IFRAME has no ID, and no name, the general situation
Position the frame and select frame (with XPath for positioning)
Webelement frame=driver.findelement (By.xpath ("/html/body/div[2]/div[8]/div[2]/div[3]/div/div[2]/div/iframe"));
Driver.switchto (). frame (frame);
3. Jump out of IFRAME
Jump out of frame, go to default content, reposition id= "Id1" div
Dr.switchto (). Defaultcontent ();
Dr.findelement (By.id ("ID1"))
4. If you are processing nested IFRAME
Business Scenario: Locate the Request product drop-down box, and then select the value action:
The page control element looks like this:
From the information point of view:
The first IFrame is written in the application Information page. The second IFrame is written in the application of the product borrowing and other content
So how do we go about positioning?
One layer at a level to jump into an iframe. Exit is also a layer of
driver. SwitchTo (). FRAME ("cont_right_show");
driver. SwitchTo (). FRAME ("addLoanApp2");
How to handle IFRAME and nested iframe in Webdriver