Python:无头模式支持旧版本的 chrome

PRK*_*PRK 1 selenium google-voice python-2.7 selenium-chromedriver

我正在尝试使用 python 和 selenium 自动发送短信https://voice.google.com/about。当我运行下面的代码时,它会获取最新版本/谷歌浏览器实例并且工作正常。但是,当我以无头模式运行它时,它使用旧版本的谷歌浏览器(从屏幕截图猜测)并给出TimeoutException()异常。登录时失败。

我在 IE 模拟器中检查了登录框的元素 id,它似乎是相同的。

        url = "https://voice.google.com/about"
        driver.get(url)
        time.sleep(5)
        driver.get_screenshot_as_file('C:\\Drivers\\Q11-0.png')

        # Click on a GET GOOGLE VOICE
        WebDriverWait(driver, 60).until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="heroToggle"]/button/span'))).click()

        print("Clicked on a get google voice")

        # Click on a WEB
        WebDriverWait(driver, 60).until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="heroToggle"]/div/button[3]'))).click()
        print("Clicked on a WEB button.")

        driver.get_screenshot_as_file('C:\\Drivers\\Q11-1.png')

        # Enter username and password
        # THIS IS WHERE IT FAILS
        WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, 'identifierId')))
        email = driver.find_element_by_id('identifierId')
        time.sleep(10)
        email.send_keys('username')
        time.sleep(10)
        nextBtn = driver.find_element_by_xpath('//*[@id="identifierNext"]/content/span')
        nextBtn.click()

        driver.get_screenshot_as_file('C:\\Drivers\\Q11-2.png')


        # Enter password
        password = driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
        password.send_keys('password')
        nextBtn = driver.find_element_by_xpath('//*[@id="passwordNext"]/content')
        nextBtn.click()
Run Code Online (Sandbox Code Playgroud)

我在正常模式下运行时的屏幕截图, 在此输入图像描述

当我在无头模式下运行时的屏幕截图, 在此输入图像描述

驱动程序已正确更新。我不确定我做错了什么。任何帮助将不胜感激。

Inf*_*rn0 5

尝试覆盖用户代理,这样它就不会包含无头标签。

opts = Options()
opts.add_argument("user-agent=User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")

driver = webdriver.Chrome(chrome_options=opts)
Run Code Online (Sandbox Code Playgroud)