The selection of elements of the Python crawler's selenium

Source: Internet
Author: User

1. Selection of individual elements

find_element_by_id find elements by Tag property ID

Find_element_by_name to find an element by using the Tag property name

Find_element_by_xpath finding elements by tag XPath path

Find_element_by_link_text find elements through element text links in tags

Find_element_by_partial_link_text

Find_element_by_tag_name by tag name Tag name find element

Find_element_by_class_name finding elements by the class property of a tag

Find_element_by_css_selector finding elements through CSS styles

2. Selection of multiple elements

Find_elements_by_name

Find_elements_by_xpath

Find_elements_by_link_text

Find_elements_by_partial_link_text

Find_elements_by_tag_name

Find_elements_by_class_name

Find_elements_by_css_selector

3. Return cookies in the current session

Driver.get_cookies ()

4. intercept the current page

Driver.get_screenshot_as_file (R "c:desktop\test.jpg")

driver.save_screenshot(‘screenshot.png‘)

5. Input Value Method

driver.find_element_by_id ("kw"). Send_keys (' admin ') Note: If the Chinese need to add u driver.find_element_by_id ("kw" ). Send_keys (u ' Youth ')

6. Simulate click action after getting element

driver.find_element_by_id ("kw"). Click ()

6. Close the browser

Driver.close ()

Driver.quit () Close the browser and eject the driver

The selection of elements of the Python crawler's selenium

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.