Cant fix the StaleElementRefereceException @my send_keys [duplicate]












1
















This question already has an answer here:




  • Stale element exception python

    2 answers



  • Selenium clicks one time, but next click returns StaleElementReferenceException

    1 answer



  • Message: stale element reference: element is not attached to the page document in Python

    1 answer




So I'm pretty new in Python and I tried something for my own, using selenium and firefox. But I got a StaleElementRefereceException when I want to type into a text field in firefox with selenium using send_key()



I tried a lot of Solutions like How to avoid "StaleElementReferenceException" in Selenium? but doesn't help me much because mine is not a click(), it's a send_key.



    hshtg = "xyz"

driver = self.driver
driver.get(".......")
#time.sleep(3)

cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
cmmnt_elem.click()
#time.sleep(3)

cmmnt_elem.send_keys(hshtg)
#time.sleep(3)
cmmnt_elem.send_keys(Keys.RETURN)


But, I got those errors.



File ".....py", line 45, in comment_photo
cmmnt_elem.send_keys(hshtg)


......



selenium.common.exceptions.StaleElementReferenceException: Message: The element 
reference of <textarea class="Ypffh"> is stale; either the element is no longer
attached to the DOM, it is not in the current frame context, or the document
has been refreshed


tried this too: (cause of this: How to avoid "StaleElementReferenceException" in Selenium?)



attempts = 0
while attempts < 20:
try:
cmmnt_elem.send_keys(hshtg)
break
except Exception as e:
attempts+1


In case it's helpful, this is the field:comment field on instagram










share|improve this question















marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • hard to tell without your xpath, but could the xpath to the textarea change based on your click?

    – Doug Clark
    Jan 2 at 20:57











  • dont thought its important, i added it!

    – Oleg Balan
    Jan 2 at 21:08
















1
















This question already has an answer here:




  • Stale element exception python

    2 answers



  • Selenium clicks one time, but next click returns StaleElementReferenceException

    1 answer



  • Message: stale element reference: element is not attached to the page document in Python

    1 answer




So I'm pretty new in Python and I tried something for my own, using selenium and firefox. But I got a StaleElementRefereceException when I want to type into a text field in firefox with selenium using send_key()



I tried a lot of Solutions like How to avoid "StaleElementReferenceException" in Selenium? but doesn't help me much because mine is not a click(), it's a send_key.



    hshtg = "xyz"

driver = self.driver
driver.get(".......")
#time.sleep(3)

cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
cmmnt_elem.click()
#time.sleep(3)

cmmnt_elem.send_keys(hshtg)
#time.sleep(3)
cmmnt_elem.send_keys(Keys.RETURN)


But, I got those errors.



File ".....py", line 45, in comment_photo
cmmnt_elem.send_keys(hshtg)


......



selenium.common.exceptions.StaleElementReferenceException: Message: The element 
reference of <textarea class="Ypffh"> is stale; either the element is no longer
attached to the DOM, it is not in the current frame context, or the document
has been refreshed


tried this too: (cause of this: How to avoid "StaleElementReferenceException" in Selenium?)



attempts = 0
while attempts < 20:
try:
cmmnt_elem.send_keys(hshtg)
break
except Exception as e:
attempts+1


In case it's helpful, this is the field:comment field on instagram










share|improve this question















marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • hard to tell without your xpath, but could the xpath to the textarea change based on your click?

    – Doug Clark
    Jan 2 at 20:57











  • dont thought its important, i added it!

    – Oleg Balan
    Jan 2 at 21:08














1












1








1









This question already has an answer here:




  • Stale element exception python

    2 answers



  • Selenium clicks one time, but next click returns StaleElementReferenceException

    1 answer



  • Message: stale element reference: element is not attached to the page document in Python

    1 answer




So I'm pretty new in Python and I tried something for my own, using selenium and firefox. But I got a StaleElementRefereceException when I want to type into a text field in firefox with selenium using send_key()



I tried a lot of Solutions like How to avoid "StaleElementReferenceException" in Selenium? but doesn't help me much because mine is not a click(), it's a send_key.



    hshtg = "xyz"

driver = self.driver
driver.get(".......")
#time.sleep(3)

cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
cmmnt_elem.click()
#time.sleep(3)

cmmnt_elem.send_keys(hshtg)
#time.sleep(3)
cmmnt_elem.send_keys(Keys.RETURN)


But, I got those errors.



File ".....py", line 45, in comment_photo
cmmnt_elem.send_keys(hshtg)


......



selenium.common.exceptions.StaleElementReferenceException: Message: The element 
reference of <textarea class="Ypffh"> is stale; either the element is no longer
attached to the DOM, it is not in the current frame context, or the document
has been refreshed


tried this too: (cause of this: How to avoid "StaleElementReferenceException" in Selenium?)



attempts = 0
while attempts < 20:
try:
cmmnt_elem.send_keys(hshtg)
break
except Exception as e:
attempts+1


In case it's helpful, this is the field:comment field on instagram










share|improve this question

















This question already has an answer here:




  • Stale element exception python

    2 answers



  • Selenium clicks one time, but next click returns StaleElementReferenceException

    1 answer



  • Message: stale element reference: element is not attached to the page document in Python

    1 answer




So I'm pretty new in Python and I tried something for my own, using selenium and firefox. But I got a StaleElementRefereceException when I want to type into a text field in firefox with selenium using send_key()



I tried a lot of Solutions like How to avoid "StaleElementReferenceException" in Selenium? but doesn't help me much because mine is not a click(), it's a send_key.



    hshtg = "xyz"

driver = self.driver
driver.get(".......")
#time.sleep(3)

cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
cmmnt_elem.click()
#time.sleep(3)

cmmnt_elem.send_keys(hshtg)
#time.sleep(3)
cmmnt_elem.send_keys(Keys.RETURN)


But, I got those errors.



File ".....py", line 45, in comment_photo
cmmnt_elem.send_keys(hshtg)


......



selenium.common.exceptions.StaleElementReferenceException: Message: The element 
reference of <textarea class="Ypffh"> is stale; either the element is no longer
attached to the DOM, it is not in the current frame context, or the document
has been refreshed


tried this too: (cause of this: How to avoid "StaleElementReferenceException" in Selenium?)



attempts = 0
while attempts < 20:
try:
cmmnt_elem.send_keys(hshtg)
break
except Exception as e:
attempts+1


In case it's helpful, this is the field:comment field on instagram





This question already has an answer here:




  • Stale element exception python

    2 answers



  • Selenium clicks one time, but next click returns StaleElementReferenceException

    1 answer



  • Message: stale element reference: element is not attached to the page document in Python

    1 answer








python selenium browser






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 22:13







Oleg Balan

















asked Jan 2 at 20:46









Oleg BalanOleg Balan

63




63




marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:26


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • hard to tell without your xpath, but could the xpath to the textarea change based on your click?

    – Doug Clark
    Jan 2 at 20:57











  • dont thought its important, i added it!

    – Oleg Balan
    Jan 2 at 21:08



















  • hard to tell without your xpath, but could the xpath to the textarea change based on your click?

    – Doug Clark
    Jan 2 at 20:57











  • dont thought its important, i added it!

    – Oleg Balan
    Jan 2 at 21:08

















hard to tell without your xpath, but could the xpath to the textarea change based on your click?

– Doug Clark
Jan 2 at 20:57





hard to tell without your xpath, but could the xpath to the textarea change based on your click?

– Doug Clark
Jan 2 at 20:57













dont thought its important, i added it!

– Oleg Balan
Jan 2 at 21:08





dont thought its important, i added it!

– Oleg Balan
Jan 2 at 21:08












1 Answer
1






active

oldest

votes


















0














when you click the textarea the DOM will be modified, so it will give the error, there are two solution to fix it.





  • remove click() action



    cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')    
    cmmnt_elem.send_keys(hshtg)



  • Re-search the element after click



    cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
    cmmnt_elem.click()

    cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
    cmmnt_elem.send_keys(hshtg)







share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    when you click the textarea the DOM will be modified, so it will give the error, there are two solution to fix it.





    • remove click() action



      cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')    
      cmmnt_elem.send_keys(hshtg)



    • Re-search the element after click



      cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
      cmmnt_elem.click()

      cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
      cmmnt_elem.send_keys(hshtg)







    share|improve this answer




























      0














      when you click the textarea the DOM will be modified, so it will give the error, there are two solution to fix it.





      • remove click() action



        cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')    
        cmmnt_elem.send_keys(hshtg)



      • Re-search the element after click



        cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
        cmmnt_elem.click()

        cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
        cmmnt_elem.send_keys(hshtg)







      share|improve this answer


























        0












        0








        0







        when you click the textarea the DOM will be modified, so it will give the error, there are two solution to fix it.





        • remove click() action



          cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')    
          cmmnt_elem.send_keys(hshtg)



        • Re-search the element after click



          cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
          cmmnt_elem.click()

          cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
          cmmnt_elem.send_keys(hshtg)







        share|improve this answer













        when you click the textarea the DOM will be modified, so it will give the error, there are two solution to fix it.





        • remove click() action



          cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')    
          cmmnt_elem.send_keys(hshtg)



        • Re-search the element after click



          cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
          cmmnt_elem.click()

          cmmnt_elem = driver.find_element_by_xpath('//textarea[@aria-label="Kommentar hinzufügen ..."]')
          cmmnt_elem.send_keys(hshtg)








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 3:14









        ewwinkewwink

        12.2k22440




        12.2k22440

















            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith