Python3+selenium Getting Started 10-form switching

Source: Internet
Author: User

When an element is in a ifarm or farm, it needs to be entered into the form before the element can be positioned for manipulation. Position the element directly. will prompt the element to not be found.

<!DOCTYPE HTML><HTML><Head></Head><Body><iframeID= ' If 'src= "Https://www.baidu.com"width= "$"Height= ' + '></iframe></Body></HTML>

Save the above HTML code in a text editor, not in a notebook in Windows. The file name is random, suffix name. html or HTM

Use Switch_to.frame () to switch the form, by default using ID or name positioning, you can directly pass the corresponding value. If you don't have an ID or name attribute, you can only navigate to it by other means and then pass it in.

 from Import  = webdriver. Chrome () Dr.maximize_window () dr.get ('file:///C:/Users/ms/Desktop/dr.html') Dr.switch_to.frame ('if'= dr.find_element_by_id ('kw  ')# Locate search Input box st.send_keys ('selenium')

You can try to remove the switch form code, it will prompt the element can not be found.

With Driver.switch_to.parent_frame (), if it is a multi-layer frame, you can jump back from the child frame to the parent frame

Use Driver.switch_to.default_content () to switch back to the main document, that is, jump out of all frame

Python3+selenium Getting Started 10-form 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.