Selenium Xpath, can someone help me with this find.element

Viewed 90

I have been really banging my head on this, I can't figure out my problem, if someone can help me it would be appreciated, thank you :).

I'm trying to select with Xpath the twitter search box, from what I know, my input is correct, since on google when I press Ctrl+F and search for it in the "inspect mode" it's highlighting in yellow the search box input tag. But in selenium, I wish it was.

(Using google chrome)

import csv
from getpass import getpass
import time
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium import webdriver


#other selenium code, working.


twitterS = driver.find_element_by_xpath('//input[contains(@data-testid,"SearchBox")]')

Return

selenium.common.exceptions.NoSuchElementException: 
Message: no such element: Unable to locate element: 
{"method":"xpath","selector":"//input[contains(@data-testid,"SearchBox")]"}

I tried the relative path, not working either

/html/body/div[1]/div/div/div[2]/main/div/div/div/div[2]/div/div[2]/div/div/div/div[1]/div/div/div/form/div[1]/div/div/div[2]/input
1 Answers

Your XPath seems to be fine (I've checked it). If Selenium tells you the elements is not there it means that it's not there in the moment it tries to find it. I don't see any frame or shadow DOM there so I would say you need to wait for this element before getting it. I would also make sure if at that point you are really on the page you're expecting to see the element at. Without the code I can't really help better.

Related