我无法点击按钮,硒

时间:2021-07-11 21:18:06

标签: python selenium

我想点击所有按钮以显示所有内容,首先我收集所有按钮,然后循环点击它们。

但我收到一个错误

<块引用>

消息:元素点击被拦截:元素在点 (1223, 15) 处不可点击。其他元素将收到点击:... (会话信息:chrome=91.0.4472.124)

from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time

URL = 'https://masterwatt.ru/catalog/kotly-gazovye-nastennye/' 

option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("prefs", { 
    "profile.default_content_setting_values.notifications": 1 
})

driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=option)

def parser_get_url_content():
    driver.get(URL)
    SCROLL_PAUSE_TIME = 0.5

    last_height = driver.execute_script("return document.body.scrollHeight")

    while True:
        driver.implicitly_wait(5) # seconds

        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

        time.sleep(SCROLL_PAUSE_TIME)

        new_height = driver.execute_script("return document.body.scrollHeight")
        if new_height == last_height:
            break
        last_height = new_height

    time.sleep(4)
    btn_plus = driver.find_elements_by_class_name('b-count__btn--plus')

    for btn in btn_plus:
        time.sleep(2)
        btn.click()
    


def get_url_content():
    pass


if __name__ == '__main__':
    parser_get_url_content()

1 个答案:

答案 0 :(得分:0)

尝试如下:

from selenium.webdriver.common.keys import Keys
    
btn.Send_keys(Keys.ENTER)