0


selenium点击span(div) 节点

背景

想用selenium来爬取知乎收藏夹的内容 ,但是不知道什么时候收藏夹的html代码发生了变化,以前画红线的部分是个button,所以直接click就行了。现在没有按钮了,是一段可以点击的缩略文字,如图1:
图1
所以就尝试点击上述的段落

问题及解决方式

用Chrome直接复制图1高亮部分的span节点的xpath(这个节点就是在段落上右键“检查”以后跳转到的节点), 这个xpath是

//*[@id="root"]/div/main/div/div[1]/div[2]/div[2]/div[1]/div[1]/div/div/div/div[2]/span/div/div/span

执行

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, location))).click()

,其中

locatioin

就是用chrome复制出来的这个节点的xpath
结果报错

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <span class="RichText ztext CopyrightRichText-richText css-4em6pe" options="[object Object]" itemprop="articleBody">...</span> is not clickable at point (796, 377). Other element would receive the click: <div class="css-79elbk">...</div> (Session info: chrome=107.0.5304.107)

注意到这一句

Other element would receive the click: <div class="css-79elbk"

因此就复制图1 高亮部分上一行的div节点的xpath了,然后这次程序就可以正常地点击这个段落了

标签: selenium chrome 前端

本文转载自: https://blog.csdn.net/weixin_43271225/article/details/128065911
版权归原作者 weixin_43271225 所有, 如有侵权,请联系我们删除。

“selenium点击span(div) 节点”的评论:

还没有评论