Im trying to get a HTML element from twitter.com search bar. Using selenium I'm using the find_element_by_xpath
method.
Code
search_input = driver.find_element_by_xpath('//input[@aria-label="Search query"]')
Error
Traceback (most recent call last):
File "C:\Users\jorda\OneDrive - Limerick Institute Of Technology\College\Semester 6\Data Analytics\Data Scraping\twit'ter.py", line 25, in <module>
search_input = driver.find_element_by_xpath('//input[@data-testid="SearchBox_Search_Input""]')
File "C:\Users\jorda\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\jorda\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\jorda\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\jorda\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //input[@data-testid="SearchBox_Search_Input""] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//input[@data-testid="SearchBox_Search_Input""]' is not a valid XPath expression.
(Session info: chrome=86.0.4240.198)
The element I'm trying to get is supposed to be aria-label="Search query"
. Any help is appreciated.