gpt4 book ai didi

python - 双击不适用于 Python 中的 headless Selenium

转载 作者:太空宇宙 更新时间:2023-11-04 00:02:55 24 4
gpt4 key购买 nike

我试图在 headless 模式下使用 selenium 双击网站上的选定元素,但是双击操作不起作用。我的 chrome 版本是 72。任何帮助将不胜感激。以下是我的代码的相关部分。

element = driver.find_element_by_id('player-forpost-html5').click()
time.sleep(5)
action = ActionChains(driver)
element_1 = driver.find_element_by_id('player-forpost-html5')
action.move_to_element(element_1)
action.double_click(element_1)
action.perform()
element_1.click()

最佳答案

对于 headless chrome 浏览器,您需要在 chrome 选项中提供窗口大小。

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('window-size=1920x1480')

请尝试一下,如果可行请告诉我。

关于python - 双击不适用于 Python 中的 headless Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55122326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com