【发布时间】:2020-07-20 10:19:56
【问题描述】:
参考访问https://rabirius.me/2020/02/14/bird-watching/(不是我的网站)
您可能会在转发按钮附近看到一个赞按钮
我希望 python 点击它,但我收到一个错误提示
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/div/div[2]/a"}
我写的代码是
for posts in open_links:
bot.get(posts)
sleep(4)
bot.find_element_by_xpath('/html/body/div/div/div[2]/a').click()
sleep(2)
like按钮的HTML是
<div class="wpl-button like">
<a href="#" title="177 bloggers like this." class="like sd-button" rel="nofollow">
<span>Like</span>
</a>
</div>
任何帮助将不胜感激
【问题讨论】:
-
你确定你有正确的 xPath 吗?我想可能是 /html/body/div/div/div[1]/a
-
检查
driver.find_element_by_css_selector("a.like.sd-button").click()
标签: python html selenium google-chrome xpath