我尝试在无头模式下使用 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()
对于无头 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')
请尝试一下并告诉我这是否有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)