简体   繁体   English

无法使用硒在instagram的评论文本框中输入文本

[英]Can't input text in comment textbox on instagram using selenium

I found the xpath of the comment box for a said user's Instagram post, and wrote a code, but I'm unable to post a comment there. 我找到了该用户的Instagram帖子的评论框的xpath,并编写了代码,但无法在此处发表评论。 Here's what I used: 这是我使用的:

com = driver.find_element_by_xpath('/html/body/span/section/main/div/div/article/div[2]/section[3]/div/form/textarea')
com.click()
com.send_keys('Cool page!')
com.send_keys(Keys.ENTER)

This is supposed to comment 'cool page!' 这应该评论“很酷的页面!” on the comment box, but it does not. 在评论框上,但事实并非如此。 When I manually click in the comment box before this part of the program runs, it works just fine, and fills in 'cool page!' 当我在程序的这一部分运行之前手动单击注释框时,它工作正常,并填写了“很酷的页面!”。 and hits submit, but without manually clicking the comment box, it does nothing. 并点击提交,但无需手动单击评论框,它不会执行任何操作。 I don't know how I would make it work. 我不知道该如何运作。

EDIT. 编辑。 HTML code by request: https://pastebin.com/trfkyQ4P HTML text area: 通过请求获得HTML代码: https : //pastebin.com/trfkyQ4P HTML文本区域:

> <textarea aria-label="Add a comment…" placeholder="Add a comment…"
> class="Ypffh" autocomplete="off" autocorrect="off" style="height:
> 18px;"></textarea>

You may need to check your xpath. 您可能需要检查xpath。

Try using the below xpath. 尝试使用下面的xpath。

 //textarea[contains(@aria-label,'Add a comment')]

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

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