Python - selenium - 消息:元素点击被拦截:元素在点处不可点击

问题描述 投票:0回答:0

下面的代码,当 headless 选项被注释掉时,工作完美,它设法点击网站上的 VIEW ALL 按钮,但是当我们包含 headless 选项时,显示错误:消息:元素点击拦截:元素是点不可点击。 我已经研究并尝试了所有可以想象的东西,但没有任何效果。 有人有什么好主意吗?谢谢

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

custom_user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"  # noqa

options = Options()
options.add_argument('--headless')
options.add_argument("start-maximized")
options.add_argument(f'user-agent={custom_user_agent}')

url = 'https://www.etf.com/SPY'

driver = webdriver.Chrome(options=options, service=Service(ChromeDriverManager().install()))  # noqa
driver.get(url)
time.sleep(3)

body = driver.find_element(By.XPATH, '/html/body')
body.send_keys(Keys.PAGE_DOWN)
body.send_keys(Keys.PAGE_DOWN)
body.send_keys(Keys.PAGE_DOWN)
body.send_keys(Keys.PAGE_DOWN)
time.sleep(3)

driver.find_element(By.XPATH, '//*[@id="holdings"]/div[2]/div[1]/div[1]/div[2]/div/div/div[1]/div[2]/div[3]/button').click()  # noqa
input('wait..')

python selenium-webdriver webdriver click
© www.soinside.com 2019 - 2024. All rights reserved.