Skip to main content
 首页 » 编程设计

python之Selenium Error : Element is not clickable at point(X, Y),其他元素会收到点击

2024年10月17日7mayingbao

我正在使用 python 和 selenium。在 this链接我会点击Reply添加评论

Element is not clickable at point (933.9500122070312, 16.666671752929688). Other element would receive the click: <a href="/create_account"></a>

代码在这里:

导入请求 从 bs4 导入 BeautifulSoup 从 gensim.summarization 导入总结

从 Selenium 导入网络驱动程序

from datetime import datetime 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.common.keys import Keys 
from time import sleep      
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.by import By 
 
    driver.get(url) 
    sleep(4) 
    f = driver.find_element_by_css_selector('.PostFull__reply') 
    f.location_once_scrolled_into_view 
    f.click() 

更新

这是它在 Inspector 中的显示方式:

请您参考如下方法:

你的 css 是正确的,长内容的问题是它将元素滚动到 .Header 下面,这就是为什么它不能点击元素。

您可以获取元素的位置并滚动到比 Y 坐标小 100px,因为 .Header 的高度为 49.5px,最好在测试前最大化窗口。见下文:

driver.maximize_window() 
f = driver.find_element_by_css_selector('.PostFull__reply') 
location = f.location["y"] - 100 
driver.execute_script("window.scrollTo(0, %d);" %location) 
f.click()