在最新版本的selenium中,已经不支持之前的元素定位方法,如find_element_by_id、find_element_by_xpath等。需将语法更改为:driver.find_element(By.ID, "username")等。特此记录。
from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() # id driver.find_element(By.ID, "username") # name driver.find_element(By.NAME, "keyword") # class name driver.find_element(By.CLASS_NAME, "login_btn") # tag_name driver.find_element(By.TAG_NAME, "select") # link_text driver.find_element(By.LINK_TEXT, "进入商城购物") # partial_link_text driver.find_element(By.PARTIAL_LINK_TEXT, "人资") # xpath driver.find_element(By.XPATH, "/html/body/div[3]/div[2]/div[3]/div/div[1]/a/img") # css_selector driver.find_element(By.CSS_SELECTOR, '[value="1"]')
标签:定位,NAME,selenium,元素,driver,element,div,find From: https://www.cnblogs.com/liusihao/p/17665483.html