首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >userAgent -selenium在设置中使用mobile_emulation或添加pytest

userAgent -selenium在设置中使用mobile_emulation或添加pytest
EN

Stack Overflow用户
提问于 2017-04-27 12:22:43
回答 1查看 740关注 0票数 3

在Selenium中,我们可以使用mobileEmulation将chrome驱动程序更改为移动模式

代码语言:javascript
复制
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中模拟手机?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-05-04 10:54:55

临时解决方案是将代码放在conftest.py上

使用收益潜水器让pytest-selenium获取驾驶员信息。

代码语言:javascript
复制
@pytest.yield_fixture
def mobileSelenium(request):
    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) 
    driver = webdriver.Chrome(chrome_options = chrome_options)
    request.node._driver = driver
    yield driver
    driver.quit()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43648637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档