简体   繁体   English

使用 selenium 和 python 对 Instagram 上的帖子发表评论,但出现错误“元素不可交互”

[英]Using selenium with python to comment on posts on Instagram but getting error "Element not interactable"

So basically, I'm using selenium to automate an instagram bot to comment on my friends posts to mess with them and to simply learn how to use selenium further.所以基本上,我正在使用 selenium 来自动化一个 instagram 机器人来评论我朋友的帖子以惹恼他们,并简单地学习如何进一步使用 selenium。

I am using the driver.find_element_by_xpath for the username and password login just fine with the .send_keys() function but when I select the comment box and try to .send_keys() to it I recieve the aforementioned error.我正在使用 driver.find_element_by_xpath 作为用户名和密码登录,使用 .send_keys() 函数就好了,但是当我选择评论框并尝试 .send_keys() 时,我收到了上述错误。 I assume this is a block by instagram to prevent this kind of behavior, but are there any workarounds?我认为这是 Instagram 阻止这种行为的一个块,但是有什么解决方法吗?

        sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/textarea')\
             .send_keys(msg)
        sleep(2)

You should have to use webdriver wait so element get ready to interact.您应该必须使用webdriver wait以便元素准备好进行交互。 Please take locator (xpath) should be correct or share html so I can make locator.请使用定位器(xpath)应该是正确的或共享 html 以便我可以制作定位器。

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 40).until(
EC.element_to_be_clickable((By.XPATH, "/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/textarea")))
element.send_keys(msg)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM