使用By定位元素,需要先导入下面语句:
from selenium.webdriver.common.by import By
find_element(By.定位的类型,定位的值)
find_element(By.ID, "kw") find_element(By.NAME, "wd") find_element(By.CLASS_NAME, "s_ipt") find_element(By.TAG_NAME, "input") find_element(By.LINK_TEXT, "新闻") find_element(By.PARTIAL_LINK_TEXT, "新") find_element(By.XPATH, "//*[@class= 'bg s_btn']") find_element(By.CSS_SELECTOR, "span.bg s_btn_wr>input#su")