" type="hidden"/>

python+selenium:點擊頁面元素時報錯:WebDriverException: Message: Element is not clickable at point (1372.5, 9.5). Other element would receive the click:

  •  
    遇到一個非常郁悶的問題,終於解決了,
    問題是這樣的,NN網站的價格計划,每一個價格計划需要三連擊才能全部點開,第一個房型的價格計划是可以正確三連擊打開的,可是第二個房弄就不行了,報錯說不是可點擊的元素,具體錯誤如下:WebDriverException: Message: Element is not clickable at point (1372.5, 9.5). Other element would receive the click: <li style="display: list-item;" id="tuanbox"></li>
     
     
     
    逐一排除:
    1) 點擊的元素被其它元素遮擋,(不是,肉眼看沒有被遮擋)
    2) 元素沒有加載出來就點擊(也不是,我加了等待時間的,而且展開的加載很快的)
    3)元素不在當前屏幕范圍內(也不是,我將鼠標移動到了當前點擊元素所在的位置了)
     
     
     
    最后在網上搜到一篇文章:做點擊操作時的錯誤WebDriverException: unknown error: Element is not clickable at point (958, 207).
     
    這里說,原因:用selenium模擬用戶單擊元素時,JS有一個操作鼠標懸浮的時候會對元素進行修改
    解決辦法:用JS來操作元素,
    沒想到真的解決了呢。^.^
     
    將:
    driver.find_element_by_xpath("//div[@class=\"room-item-inner room-item-wrapper\"][" + str(i) + "]//a[@class=\"js-expand-more\"]").click
    改為:

    button = driver.find_element_by_xpath("//div[@class=\"room-item-inner room-item-wrapper\"][" + str(i) + "]//a[@class=\"js-expand-more\"]")
    driver.execute_script("$(arguments[0]).click()",button)
     
    selenium+python使用js點擊元素:https://blog.csdn.net/u012189659/article/details/38496059
     
     
    其他參考:selenium 之Action Chains類:https://www.cnblogs.com/cnkai/p/7538267.html


    免責聲明!

    本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



     
    粵ICP備18138465號   © 2018-2025 CODEPRJ.COM