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
  • 相关阅读:
    Codeforces 512D
    Codeforces Gym 101480C
    Codeforces 575A
    Codeforces Round #691 (Div. 2) 题解
    .net Core 中文等非英文文字html输出编码输出问题
    .net5 grpc服务在windows上的架设方法
    北大集训 2020 游记
    北大集训2020游记
    Tricks -「网络流」经典模型汇总
    Solution -「BJWC 2018」「洛谷 P4486」Kakuro
  • 原文地址:https://www.cnblogs.com/tester-study/p/8416209.html
Copyright © 2011-2022 走看看