zoukankan      html  css  js  c++  java
  • Selenium +Chrome浏览器如何模拟手机操作

    Selenium +Chrome浏览器如何模拟手机操作
    • 进入手机模式
    1. 打开谷歌浏览器,按F12,进入开发者模式,点击Toggle device toolbar,进入手机模式

    • 设置Chrome的手机模式
    deviceName可更改成Chrome浏览器中支持的设备型号
    • 设置成手机模式之后,使用click事件,进行搜索,无响应,我们可以使用TouchActions中tap方式去处理
    • TouchActions具体可参看源码
    示例代码:
    # -*- coding:utf-8 -*-
    from seleniumimportwebdriver
    from selenium.webdriver.common.touch_actionsimportTouchActions
    mobile_emulation = {"deviceName":"Galaxy S5"}
    option = webdriver.ChromeOptions()
    option.add_experimental_option('mobileEmulation',mobile_emulation)
    driver = webdriver.Chrome(chrome_options=option)
    driver.get('https://www.baidu.com')
    print('打开浏览器')
    print(driver.title)
    driver.find_element_by_id('index-kw').send_keys('测试')
    # driver.find_element_by_id("index-bn").click()
    el = driver.find_element_by_id("index-bn")
    TouchActions(driver).tap(el).perform()
    print('关闭')
    driver.quit()
    print('测试完成')

    《接口测试自动化实战》 https://yuedu.baidu.com/ebook/aaf72f1b42323968011ca300a6c30c225901f07d 《python+appium自动化项目实战》 https://yuedu.baidu.com/ebook/765b38a5690203d8ce2f0066f5335a8102d266b9[/b]6f5335a8102d266b9
  • 相关阅读:
    程序自动更新版本
    [.NET] Rough Dependency Injection
    Python标准库存储对象(pickle包,cPickle包)
    发送邮件,支持群发
    css3传送带示例
    “计算机之子”的MVVM框架源码学习笔记
    Windows 8 应用商店正式面向全部开发者开放
    MVVM框架 v1发布
    Python学习索引
    注册 windows 8 开发者账号
  • 原文地址:https://www.cnblogs.com/tester-study/p/8416209.html
Copyright © 2011-2022 走看看