def getFollowers(self):
self.browser.get(f"https://www.instagram.com/{self.username}")
time.sleep(2)
// I have a problem with the XPath in this line
self.browser.find_element_by_xpath("//*[@id='react-root']/section/main/div/ul/li[2]/a").click()
time.sleep(2)
I'm pretty new to Python. I wrote the exact code described in the lesson above and shared a part of it here. There is a problem with the line after the comment.
What alternative can I use to find_element_by_xpath
code? Also, how should it be used?
Although I copied the code from the tutorial, I get errors and I don't understand why. The error is below.
DevTools listening on ws://127.0.0.1:65233/devtools/browser/f0005e34-6939-40d0-8480-d4ff3ad06845
Traceback (most recent call last):
File "_instagram.py", line 59, in <module>
instagrm.getFollowers()
File "_instagram.py", line 27, in getFollowers
self.browser.find_element_by_xpath("//*[@id='react-root']/section/main/div/ul/li[2]/a").click()
File "C:\Users\sunaercan\AppData\Local\Programs\Python\Python38\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\sunaercan\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\sunaercan\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\sunaercan\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='react-root']/section/main/div/ul/li[2]/a"}
(Session info: chrome=84.0.4147.125)