要使用find_element(),使用前导入
from selenium.webdriver.common.by import By
和
from selenium.common.exceptions import NoSuchElementException
在from selenium import webdriver之后
find_element()内容:
使用class_name: button = driver.find_element_by_class_name("quiz_button") 需要替换为: button = driver.find_element(By.CLASS_NAME, "quiz_button") 使用id: element = find_element_by_id("element_id") 需要替换为: element = driver.find_element(By.ID, "element_id") 使用name: element = find_element_by_name("element_name") 需要替换为: element = driver.find_element(By.NAME, "element_name") 使用link_text: element = find_element_by_link_text("element_link_text") 需要替换为: element = driver.find_element(By.LINK_TEXT, "element_link_text") 使用partial_link_text: element = find_element_by_partial_link_text("element_partial_link_text") 需要替换为: element = driver.find_element(By.PARTIAL_LINK_TEXT, "element_partial_link_text") 使用tag_name: element = find_element_by_tag_name("element_tag_name") 需要替换为: element = driver.find_element(By.TAG_NAME, "element_tag_name") 使用css_selector: element = find_element_by_css_selector("element_css_selector") 需要替换为: element = driver.find_element(By.CSS_SELECTOR, "element_css_selector") 使用xpath: element = find_element_by_xpath("element_xpath") 需要替换为: element = driver.find_element(By.XPATH, "element_xpath")