【问题标题】:Double Click does not work with headless Selenium in PythonDouble Click 不适用于 Python 中的无头 Selenium
【发布时间】:2019-03-12 13:13:17
【问题描述】:

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

【问题讨论】:

    标签: python selenium selenium-chromedriver google-chrome-headless


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-20
      • 2023-01-17
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 2021-12-25
      • 2023-01-13
      • 2014-09-04
      相关资源
      最近更新 更多