欢迎关注微信公众号交流: 零基础学自动化测试 《接口测试自动化实战》--接口自动化书籍 https://yuedu.baidu.com/ebook/aaf72f1b42323968011ca300a6c30c225901f07d 欢迎阅读

Python - selenium自动化-Chrome(wap模式)

上一篇 / 下一篇  2018-01-11 13:57:54

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

  • 设置Chrome的手机模式
deviceName可更改成Chrome浏览器中支持的设备型号
  • 设置成手机模式之后,使用click事件,进行搜索,无响应,我们可以使用TouchActions中tap方式去处理
  • TouchActions具体可参看源码
示例代码:
# -*- coding:utf-8 -*-
fromseleniumimportwebdriver
fromselenium.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('测试完成')
Miss_love

Miss_love

《接口测试自动化实战》-接口测试书籍 https://yuedu.baidu.com/ebook/aaf72f1b42323968011ca300a6c30c225901f07d

日历

« 2024-03-28  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 24793
  • 日志数: 24
  • 图片数: 1
  • 建立时间: 2017-09-11
  • 更新时间: 2019-12-04

RSS订阅

Open Toolbar