Selenium find_element_by_* 方法的替换方案

DeprecationWarning

DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  input_second = browser.find_element_by_css_selector('#q')

find_element_by_* 方法的替换方案

  • find_element_by_id('kw') 👉 find_element(By.ID,'kw')

  • find_element_by_css_selector('#q') 👉 find_element(By.CSS_SELECTOR,'#q')

  • find_element_by_xpath('//*[@id="q"]') 👉 find_element(By.XPATH,'//*[@id="q"]')

...

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"

From 👉 https://github.com/SeleniumHQ/selenium/blob/trunk/py/selenium/webdriver/common/by.py

posted @ 2021-12-10 16:03  javakam  阅读(39)  评论(0)    收藏  举报  来源