在尝试在heroku上模拟带有chrome的移动浏览器时遇到了以下问题:Selenium ERR_NAME_NOT_RESOLVED on heroku with mobile testing。基于Josh Lewis的答案以及https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation
处的python代码示例from selenium import webdriver
mobile_emulation = { "deviceName": "Nexus 5" }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities = chrome_options.to_capabilities())
可能是我需要将command_executor(在https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html上定义)用作
command_executor - Either a string representing URL of the remote server or a
custom
remote_connection.RemoteConnection object. Defaults to
‘http://127.0.0.1:4444/wd/hub'
使我的代码正常工作。我如何通过Heroku chrome构建包https://github.com/heroku/heroku-buildpack-google-chrome
找到它编辑:
您可以在以下位置下载适用于Windows和Heroku的项目:
https://github.com/kc1/mobiletest
(请记住,如果您部署到heroku,则必须将FLASK_CONFIG设置为生产。)