selenium-find_element content (2)

The difference find_element with find_element_by_xxx

1. Check the file D: \ soft \ python36 \ Lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py can be found find_element method find_element_by_xxx methods are returned

2. View the file D: \ soft \ python36 \ Lib \ site-packages \ selenium \ webdriver \ common \ by.py can be found

class By(object):
    """
    Set of supported locator strategies.
    """

    ID = "id"
    XPATH = "xpath"
    LINK_TEXT = "link text"
    PARTIAL_LINK_TEXT = "partial link text"
    NAME = "name"
    TAG_NAME = "tag name"
    CLASS_NAME = "class name"
    CSS_SELECTOR = "css selector"

Understand the above example, click on the red font achieve Baidu, three methods are equivalent:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
time.sleep(2)
driver.find_element(By.CSS_SELECTOR,".btn_wr>input").click()
# driver.find_element("css selector",".btn_wr>input").click()
# driver.find_element_by_css_selector(".btn_wr>input").click()
time.sleep(2)
driver.quit()

 find_element the  difference of find_elements

find_element get is an element

find_elements get is a list of

Guess you like

Origin www.cnblogs.com/wang-mengmeng/p/11497136.html