通过找到find_element方法的定义
将代码改成这样:
import time
from selenium import webdriver
driver = webdriver.Edge()
driver.get("https://www.csdn.net/")
driver.find_element(by=By.ID, value='toolbar-search-input').send_keys('python')
driver.find_element(by=By.ID, value='toolbar-search-button').click()
time.sleep(6)
driver.quit()
又报了这个错误,那么就import一下。
最后终于能运行的代码:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://www.csdn.net/")
driver.find_element(by=By.ID, value='toolbar-search-input').send_keys('python')
driver.find_element(by=By.ID, value='toolbar-search-button').click()
time.sleep(6)
driver.quit()