Python Selenium Webdriver (name 'by' not defined)


Question

I keep getting an error as below:

NameError: name 'By' is not defined

for the code

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]')))  

Is my import correct?

1
5
9/19/2017 7:09:25 AM

you have to import it

from selenium.webdriver.common.by import By
15
6/19/2017 12:00:37 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon