我使用所需的包创建了virtualenv。激活了环境。现在我继续得到以下内容:ImportError: cannot import name webdriver
。我检查了我的环境,我的所有文件似乎都是正确的。谁能提供输入?我包括代码丢弃链接和屏幕截图。
https://drive.google.com/open?id=1jzVoBilX9pU3CYC2czQ3IBRE87sCWJ3k
import time
from selenium import webdriver # this is the offending line
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
def init_driver():
driver = webdriver.Firefox()
driver.wait = WebDriverWait(driver, 5)
return driver
def lookup(driver, query):
driver.get("http://www.google.com")
try:
box = driver.wait.until(EC.presence_of_element_located(
(By.NAME, "q")))
button = driver.wait.until(EC.element_to_be_clickable(
(By.NAME, "btnK")))
box.send_keys(query)
button.click()
except TimeoutException:
print("Box or Button not found in google.com")
if __name__ == "__main__":
driver = init_driver()
lookup(driver, "Selenium")
time.sleep(5)
driver.quit()