问题
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