双击不能在Python中使用headless Selenium

2024-09-30 18:21:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在无头模式下双击使用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()

Tags: id元素by网站driverselenium模式action
1条回答
网友
1楼 · 发布于 2024-09-30 18:21:53

对于无头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')

请试试看,如果行得通请告诉我。在

相关问题 更多 >