Search code examples
pythonseleniumselenium-webdriverwebdriverselenium-webdriver-python

AttributeError: module 'selenium.webdriver.common.by' has no attribute 'XPATH' using Selenium Python


I'm starting in programming, so I created a simple code, but it's giving this error:

enter image description here

I'm using Jupyter Notebook, this is the code, if anyone knows what the problem is, please help me

enter image description here


Solution

  • As the error already tells you, by.XPATH doesn't exist. But by has a class called By and it's attribute XPATH.

    Like that:

    from selenium.webdriver.common.by import By
    
    driver = ...
    elem = driver.find_element(By.XPATH, "YOUR_XPATH")