Reputation: 1
i'm trying to automate comments under an ig post but it doesn't work. it gives a generic send_keys error. the script crashes after clicking the ig comment box.
class InstagramBot:
def autocomment(self):
driver = self.driver
comment_box = driver.find_element_by_class_name("Ypffh")
comment_box.clear()
time.sleep(2)
comment_box.send_keys(self.comment)
time.sleep(10)
if name == "main":
username = "test"
password = "test"
ig = InstagramBot(username, password)
ig.login()
ig.nav_user()
while True:
ig.autocomment()
error: File "C:\Users\Utente\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys 'value': keys_to_typing(value)})
Upvotes: 0
Views: 446
Reputation: 31
Supposing you are already logged in and inside a post the code below should work fine.
def autocomment(self, profile_name, comment):
driver = self.driver
driver.get("https://www.instagram.com/" + profile_name + "/")
time.sleep(2)
comment_box = driver.find_element_by_class_name('Ypffh')
comment_box.click()
comment_box = driver.find_element_by_class_name('Ypffh')
comment_box.send_keys(comment)
comment_box.send_keys(Keys.ENTER)
ig.autocomment("profile_name", "blabla")
As far as your code concerned :
comment_box.send_keys(self.comment)
After commenting you should have had submitted it in some way.
Last but not least I don't think this line below is necessary as every-time the comment box is empty by default.
comment_box.clear()
For any additional help please tell me as it's my first time answering a question.
Upvotes: 2