【发布时间】:2017-04-27 04:22:42
【问题描述】:
在 Selenium 中,我们可以使用 mobileEmulation 将 chrome 驱动程序更改为移动模式
mobile_emulation = {
"deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
"userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
chrome_options = Options()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
webdriver.Chrome(chrome_options = chrome_options)
我检查了 pytest-selenium 有功能选项,但不适用于用户代理
我有什么解决方案可以在 pytest-selenium 中模拟移动设备吗?
谢谢
【问题讨论】:
-
这看起来像来自example 的代码。 “不工作”是什么意思?怎么了?你有错误吗?
-
哦,我想使用 pytest-selenium 报告,所以我想将 useragent 传递给它,似乎不起作用,chrome 浏览器对 useragent 和指标无效
-
恐怕我还不清楚。您能否准确展示您当前看到的内容,以及如果它正常工作您希望看到的内容?
标签: python selenium selenium-webdriver pytest