![](/img/trans.png)
[英]NameError: name 'webdriver' is not defined error using Selenium and Python
[英]Error "name 'by' is not defined" using Python Selenium WebDriver
我不斷收到如下錯誤:
NameError:名稱“By”未定義
對於代碼
chrome_driver_path = r"C:\chromedriver.exe"
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
browser = webdriver.Chrome(chrome_driver_path)
browser.delete_all_cookies()
browser.get("https://www.google.com/")
wait = WebDriverWait(browser, 10)
element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tsf"]/div[2]/div[3]/center/input[1]')))
我的導入正確嗎?
你必須導入它
from selenium.webdriver.common.by import By
您可以導入By
使用
selenium.webdriver.common.by import By
在代碼頂部添加這一行解決了我的問題:
from selenium.webdriver.common.by import By
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.