selenium启动chrome模拟器模拟手机
一、如果chrome选项里边有这个模拟设备(比如iPhone 6 Plus):
1、先启动Selenium Grid, 比如命令:java -jar selenium-server-standalone-XXX.jar。
2、代码如下:
#coding=utf-8
from selenium import webdriver mobile_emulation = { "deviceName": "iPhone 6 Plus" }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities = chrome_options.to_capabilities())
二、如果chrome选项里边没有预置这个模拟设备,也可以自己配置,代码如下:
#coding=utf-8
from selenium import webdriver mobile_emulation = {
"deviceMetrics": { "width": 414, "height": 736, "pixelRatio": 3.0 },
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1" }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(chrome_options = chrome_options)
三、修改浏览器的User-Agent来伪装你的浏览器访问手机m站,代码如下:
#coding=utf-8
from selenium import webdriver chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1')
driver = webdriver.Chrome(chrome_options = chrome_options)
selenium启动chrome模拟器模拟手机的更多相关文章
- selenium启动Chrome时,加载用户配置文件
selenium启动Chrome时,加载用户配置文件 Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome ...
- selenium+python自动化100-centos上搭建selenium启动chrome浏览器headless无界面模式
环境准备 前言 selenium在windows机器上运行,每次会启动界面,运行很不稳定.于是想到用chrome来了的headless无界面模式,确实方便了不少. 为了提高自动化运行的效率和稳定性,于 ...
- Selenium启动Chrome浏览器提示“请停用以开发者模式运行的扩展程序”的解决办法
安装了python selenium,运行下面代码: 1 from selenium import webdriver 2 3 browser = webdriver.Chrome() 4 brows ...
- 用Chrome浏览器模拟手机,android,iphone,ipad访问网站
很多网站都通过User-Agent来判断浏览器类型,如果是3G手机,显示手机页面内容,如果是普通浏览器,显示普通网页内容.谷歌Chrome浏览 器,可以很方便地用来当3G手机模拟器.在Windows的 ...
- 用selenium启动chrome浏览器
python 3.7 pycharm 1.安装selenium pip3 install selenium 2.下载与chrome匹配的chromdriver.exe,放到项目的解释器路径下,跟pyt ...
- selenium启动Chrome浏览器和禁止证书错误提示弹出
要把ChromeDriver放到代码中的文件夹中c://*******Application public static WebDriver WebDriverRun(WebDriver driver ...
- selenium启动chrome出错处理:Message: 'chromedriver' executable needs to be in PATH
- robotframework_如何用Chrome模拟手机打开H5页面
由于公司目前的产品大部分都是APP端的H5页面,APP原生页面很少,测试H5页面如果去搭建appium或者macaca这类自动化平台太费时,太重而不能快速落地:与自动化的目标:提高测试效率相悖.但如果 ...
- chrome模拟手机功能
在搭建好web側环境之后.能够使用chrome来模拟手机的功能 直接上图吧: 图1是直接模拟一个通用的界面 图2里面能够选择不同的手机型号,还是比較全的! 选择一个查看一下,和手机是一样的效果,非常赞 ...
随机推荐
- [BZOJ4103][Thu Summer Camp 2015]异或运算 可持久化Trie树
4103: [Thu Summer Camp 2015]异或运算 Time Limit: 20 Sec Memory Limit: 512 MB Description 给定长度为n的数列X={x1 ...
- [NOI2017]蚯蚓排队 hash
题面:洛谷 题解: 我们暴力维护当前所有队伍内的所有子串(长度k = 1 ~ 50)的出现次数. 把每个子串都用一个hash值来表示,每次改变队伍形态都用双向链表维护,并暴力更新出现次数. 现在考虑复 ...
- [POI2012]OKR-A Horrible Poem hash
题面:洛谷 题解: 首先我们需要知道一个性质,串s的最小循环节 = len - next[len].其中next[len]表示串s的一个最长长度使得s[1] ~ s[next[len]] == s[l ...
- Java试题二
QUESTION 37Given:1. class Super {2. private int a;3. protected Super(int a) { this.a = a; }4. } ...1 ...
- VSAM:视频监控系统 A System for Video Surveillance and Monitoring
VSAM(VideoSurveillance and Monitoring)视频监控系统 Robotics Institute CMU 1:引言 2:试验床介绍 3:基本的视频分析算法:运动目标检测, ...
- Codeforces243A The Brand New Function
A. The Brand New Function time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- spring整合hibernate时报错:org.hibernte.engine.transaction.spi.transactioncontext
错误提示:Caused by:java.lang.ClassNotFoundException: org.hibernte.engine.transaction.spi.transactioncont ...
- (转)MySQL建表设置两个默认CURRENT_TIMESTAMP的技巧
业务场景: 例如用户表,我们需要建一个字段是创建时间, 一个字段是更新时间. 解决办法可以是指定插入时间,也可以使用数据库的默认时间. 在mysql中如果设置两个默认CURRENT_TIMESTAMP ...
- [DeeplearningAI笔记]卷积神经网络1.2-1.3边缘检测
4.1卷积神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.2边缘检测示例 边缘检测可以视为横向边缘检测和纵向边缘检测如下图所示: 边缘检测的原理是通过一个特定构造的卷积核对原始图 ...
- MSBuild问题积累
我想要当属性ConfigurationType定义为StaticLibrary时,将其重新定义为StaticLibrary,按照以下来做,实现不了. <ConfigurationType> ...