im trying to learn selenium by making a bot that goes to an instagram account and comments on a post
this is my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
site = webdriver.Edge('C:\\P\\Automation\\MicrosoftWebDriver')
site.get('https://www.instagram.com/example_account/')
ref = site.find_element_by_xpath("//*[@id=\"reactroot\"]/section/main/div/div/article/div[1]/div/div[1]/div[1]/a")
site.get(ref.get_attribute('href'))
txt = site.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div/article/div[2]/section[3]/form/textarea')
txt.send_keys('test')
txt.send_keys(Keys.ENTER)
the problem is that when i send keys to the comment element
<textarea aria-label="Add a comment…" placeholder="Add a comment…" class="Ypffh" autocomplete="off" autocorrect="off" style="height: 18px;"></textarea>
it does nothing the first i try to send keys time and the second time i run the command:
txt.send_keys('test')
it gives me an error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: Stale element reference
would love some help, thanks!