I'm starting in programming, so I created a simple code, but it's giving this error:
I'm using Jupyter Notebook, this is the code, if anyone knows what the problem is, please help me
CodePudding user response:
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")
CodePudding user response:
XPATH and other locator strategies are implemented through the By implementation:
"""
The By implementation.
"""
class By(object):
"""
Set of supported locator strategies.
"""
ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
So essentially you have to import By from selenium.webdriver.common.by
. Hence, the import statement should have been:
from selenium.webdriver.common.by import By
and then you can use:
driver.find_element(By.XPATH, '//*[@id="i0116"]').send_keys("TESTE")