Python+selenium Learning Note 8-Multiple Forms & Multi-window switching

Source: Internet
Author: User

1. Multi-form switching

For test page: Embedded Baidu homepage

Switch to Baidu homepage for operation

1 #coding = Utf-82 3  fromSeleniumImportWebdriver4 ImportOS5 Import Time6 7Dr =Webdriver. Firefox ()8File_path ='file:///'+ Os.path.abspath ('frame.html')9 dr.get (File_path)Ten  One #Switch to iframe (id= "if") ADr.switch_to.frame ("if") -  -DR.FIND_ELEMENT_BY_ID ("kw"). Send_keys ("Selenium") theDR.FIND_ELEMENT_BY_ID ("kw"). Submit () -Time.sleep (3) -  -Dr.close ()

Switch_to.frame () can take the ID of the form or the Name property directly. If the IFRAME does not have an ID and a name attribute available. Can be positioned in the following ways

...... # first through XPath to the iframeXF = driver.find_element_by_xpath ('//*[@class = "If"]  #  then pass the anchored object to the Switch_to.frame () method driver.switch_to.frame (XF) ... driver.switch_to.parent _frame ()

There are other ways switch_to.parent_content (), Switch_to.default_content ()

I didn't use any of these methods.

Python+selenium Learning Note 8-Multiple Forms & Multi-window switching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.