selenium以手机模拟器方式打开Google浏览器
使用chrome driver和chrome浏览器并进入chrome的 toggle device mode 模式,就可以很好的模拟手机端,下面直接上代码
public class runtest {
WebDriver driver;
@BeforeClass
public void beforeClass(){
System.setProperty("webdriver.chrome.driver", "C:\Windows\System32\chromedriver.exe");
Map<String, String> mobileEmulation = new HashMap<String, String>();
//设置设备,例如:iPhone X
mobileEmulation.put("deviceName", "iPhone X"); //这里是要使用的模拟器名称,就是浏览器中模拟器中的顶部型号
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
try {
driver = new ChromeDriver(capabilities);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@Test
public void run(){
driver.get("http://m.baidu.com/");
}
设备的名称,名称要一致,否则会出错

selenium以手机模拟器方式打开Google浏览器的更多相关文章
- Java实现打开google浏览器
说明: 博主的Google浏览器版本:75.0.3770.142,如果运行异常,需要自行查找对应版本的驱动(chromedriver.exe) 需要的jar包: https://pan.baidu.c ...
- Python+selenium学习(一) 打开Firefox浏览器,IE浏览器和Chrome浏览器
from selenium import webdriver # open Firefox #driver=webdriver.Firefox() # Open IE #driver=webdrive ...
- 用selenium控制已打开的浏览器
在使用selenium进行自动化测试会遇到,手工打开浏览器,做了一部分操作后,并打开相关页面后再执行相关的自动化脚本. 如何使用selenium来接管先前已打开的浏览器呢?醍提出一个Google Ch ...
- google浏览器插件fq教程
google插件fq教程 思路 谷歌浏览器的应用市场 上有很多vp恩插件,不过要能访问谷歌浏览器的应用市场就得fq出去才行,而有一个很棒的插件就可以访问谷歌的旗下的一些东西,例如邮箱,Google搜索 ...
- ubuntun 18.04 安装google浏览器
---恢复内容开始--- 一:下载谷歌浏览器镜像源 sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/ap ...
- Google浏览器出现崩溃问题解决
更新google浏览器79版本后所有页面出现崩溃情况,在试过加no-sandbox和兼容模式之后还是不太满意,后来搜到可能是网络问题,然后打开google浏览器安装文件夹,发现chrome_proxy ...
- selenium:能够模拟人类打开浏览器的爬虫利器
介绍 selenium相当于是一个机器人,可以模拟人类登陆浏览器的行为,比如点击.填充数据.删除cookie等等.Chromedriver是一个驱动Chrome的程序,使用它才可以驱动浏览器,其实Ch ...
- Chrome浏览器内嵌的各种手机模拟器
打开chrome的控制台标签,然后,点击simulator子标签页,选择需要的手机即可,如下图: 模拟器如下: 阅读原文:Chrome浏览器内嵌的各种手机模拟器
- 使用python+selenium控制手工已打开的浏览器
我们可以利用Chrome DevTools协议.它允许客户检查和调试Chrome浏览器. 打开cmd,在命令行中输入命令: chrome.exe --remote-debugging-port=922 ...
随机推荐
- (十一)__LINE__、__FUNCTION__的使用
单片机中也可以用__LINE和__FUNCTION__进行异常信息打印,分别代表当前代码行数和当前代码函数名 printf("line:%d\r\n",__LINE__); pri ...
- 简单粗暴的webapp语言国际化
不同语言以json格式存放不同文件 { "information": "个人资料", "fuckworld":"你好世界" ...
- shell里面比较大小
#!/bin/bashif [ $1 -gt $2 ]then echo "$1>$2"else echo "$2>$1"fi# 数字判断一些命令 ...
- cmake 查找头文件和库文件顺序
cmake会先到*_DIR里指定.cmake文件里去找找不到了才会到/usr里去找 所以要小心cmake给你找的文件,如果在一台电脑里装了不止一个版本库.
- opencv对鼠标的响应
#include <cv.h> #include <highgui.h> #include <stdio.h> #pragma comment(lib,&quo ...
- codeforces 869A The Artful Expedient【暴力枚举/亦或性质】
A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...
- Retrying Operations using Spring's RetryTemplate
If your application is using Spring then it is easier to use the Spring Framework's RetryTemplate. T ...
- Linux CentOS下Python+robot framework环境搭建
转载自:http://blog.sina.com.cn/s/blog_13cc013b50102vof1.html 操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.c ...
- JDK/Java里的设计模式
JDK/Java里的设计模式
- POJ 3709 K-Anonymous Sequence(斜率优化DP)
[题目链接] http://poj.org/problem?id=3709 [题目大意] 给出一个长度为n个非严格单调递增数列,每次操作可以使得其中任意一项减一, 问现在使得数列中每项数相同的数的数量 ...