Home > Back-end >  Instagram selenium post button not working
Instagram selenium post button not working

Time:03-07

I recently used selenium code to post a comment on one of my favorite posts. Everything works fine except when the comment is written in the text field and it must then be posted. how can I fix this issue?

 driver.find_element_by_class_name('Ypffh').click()  # click the field to insert comment
 field = driver.find_element_by_class_name('Ypffh')
 field.clear()
 typephrase(comment[counter], field)  
 sleep(delay)

The blow code does not work for posting comments. How can I fix it?

driver.find_element_by_xpath('//button[contains(text(), "Post")]').click()  # click the post 'comment' button element

CodePudding user response:

If it is a comment you are trying to post then I believe you don't have to click the post button, you could instead send the enter key to the text box element and this will post the comment. This will also be helpful, because it will still work if they ever change the HTML x-path of the post button element.

This is how I would do it, using your code from the first part:

from selenium.webdriver.common.keys import Keys

driver.find_element_by_class_name('Ypffh').click()  # click the field to insert comment
field = driver.find_element_by_class_name('Ypffh')
field.clear()
typephrase(comment[counter], field)  
sleep(delay)

field.send_keys(Keys.ENTER)

I hope that helps, sorry if it doesn't!

  • Related