Selenium報錯:element click intercepted: Element is not clickable at point ,Other element would receive
阿新 • • 發佈:2021-02-08
錯誤日誌:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element xxxis not clickable at point (374, 25). Other element would receive the click: xxx
在使用selenium模擬瀏覽器的點選動作時,出現錯誤:
確定頁面上確實存在對應的按鈕:
經過查詢資料排查,發現問題:被觸發點選事件的按鈕不在瀏覽器的視窗內,即需要滑動滾動條才可以看到:
參考頁面:https://blog.csdn.net/weixin_44679832/article/details/104387860
解決方案:
由於需要觸發的按鈕在頁面頂部,將滾動條回到頂部,再觸發click事件,即可:
# 滾動到瀏覽器頂部
def scroll_to_top(driver):
js_top = "var q=document.documentElement.scrollTop=0"
# 初始化現在滾動條所在高度為0
driver.execute_script(js_top)