Issue
I am fairly new in Selenium and I've been trying to work on automating the login for this [website], but for some reason element.click()
on selenium does not seem to work when I try to click onto the Login button. I keep getting this TypeError: 'str' object is not callable
error.
Here's my code:
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH("//li[@class='item-119']/a[contains(text(),'Login')]")))
)
print("TEST")
element.click()
finally:
driver.quit()
I've also tried using By.CLASS_NAME
and By.PARTIAL_LINK_TEXT
and I keep getting the same error. Spent a few hours researching, looking through StackOverFlow and trying to solve this error but I don't seem to be able to solve it. Please do help me and let me know where I went wrong.
Solution
You are trying to use wrong locator.
Selenium fails to find such element.
Also, it's better to use expected conditions of element visibility instead of element presence since when element becomes existing on the page it is still not clickable / visible.
So, please try this:
element = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@id='header']//a[@class='login-btn']")))
print("TEST")
element.click()
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.