Double Click does not work with headless Selenium in Python

ⅰ亾dé卋堺 提交于 2021-02-10 08:02:56

问题


Im trying to double click on a selected element on a website using selenium in headless mode, however the double click action does not work. My chrome version is 72. Any help would be greatly appreciated. Below is the relevant portion of my code.

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()

回答1:


For headless chrome browser you need to provide window size as well in chrome options.

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')

Please try that and let me know if this work.



来源:https://stackoverflow.com/questions/55122326/double-click-does-not-work-with-headless-selenium-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!