I am writing a script in python that logs in twitter however whenever i try to locate the log-in button in selenium it gives an error
Python code:
driver= webdriver.Firefox()
driver.get("https://twitter.com")
login_button= driver.find_element(By.XPATH, "//a[@href='/i/flow/signup']") print(login_button)
Source of the target element:
The error:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //a[@href='/i/flow/signup']
I have even tried copying the absolute path of the element:
driver= webdriver.Firefox()
driver.get("https://twitter.com")
login_button= driver.find_element(By.XPATH, "/html/body/div/div/div/div[2]/main/div/div/div[1]/div[1]/div/div[3]/a")
print(login_button)
This gives the error:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: /html/body/div/div/div/div\[2\]/main/div/div/div\[1\]/div\[1\]/div/div\[3\]/a
CodePudding user response:
As error says: Unable to locate element. You can use wait to "wait" until your element is located. For more you can see: