簡體   English   中英

如何向上滾動,然后使用Selenium和python單擊

[英]How do I scroll up and then click with Selenium and python

我需要在python中使用硒單擊按鈕。 這就是我所擁有的:

read_more_buttons = responses[0].find_elements_by_class_name("read-more")
            if len(read_more_buttons) > 0:
                read_more_buttons[0].click()

在大多數情況下,它都能正常工作,但有時頁面底部會有一個疊加層,無法消除。 因此,我會收到此錯誤:

[element] is not clickable at point (665.7333145141602,883.4666748046875) because another element <div class="raq-module js-raq-module"> obscures it

我試圖在調用click()之前使用此代碼向下滾動頁面:

driver.execute_script("window.scrollTo(0, " + str(read_more_buttons[0].location["y"] + 120) + ")") 

但是,我仍然收到相同的錯誤。 似乎通過調用.click()該元素將滾動到頁面的最底部,該頁面.click()位於疊加層的下方。 如何上移頁面,然后單擊?

那些當鋪!

在這里,讓我們嘗試使用JS 滾動到視圖中 ,然后單擊

read_more_buttons = responses[0].find_elements_by_class_name("read-more")
if len(read_more_buttons) > 0:
    driver.execute_script("arguments[0].scrollIntoView(true);", read_more_buttons[0])
    driver.execute_script("arguments[0].click()", read_more_buttons[0])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM