0
from selenium import webdriver
import os

os.environ['PATH'] += "C:\\Users\\czoca\\PycharmProjects\\pythonProject4\\chromedriver.exe"

driver = webdriver.Chrome()
driver.get("https://www.teintes.fr/p/recapitulatif.html")
driver.implicitly_wait(10)
myelement1 = driver.find_element(By.ID, "Autoriser")
myelement = driver.find_element(By.ID, "Carens III")
myelement1.click()
myelement.click()

This is giving me this error: ""Traceback (most recent call last): File "C:\Users\czoca\PycharmProjects\imagesscraping\main.py", line 9, in myelement1 = driver.find_element(By.ID, "Autoriser") ^^ NameError: name 'By' is not definedenter image description here

Nolgath
  • 25
  • 3

3 Answers3

0

You are missing the import of 'By' from the package selenium. You can import it like so:

from selenium.webdriver.common.by import By

You can look up more details about selenium on the docs

0

Add the following import to your file:

from selenium.webdriver.common.by import By

And it should be good.

0

You need to import the By module from Selenium in order to use it ( I agree that it is not obvious at first time), by simply adding this line from selenium.webdriver.common.by import By

You will also probably need thoses packages :

# Import required packages
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver import EdgeOptions

Hope I helped you

Have a good day

iD_Sgh
  • 108
  • 1
  • 5