selenium以手机浏览模式打开浏览器
2017-02-22 10:25
253 查看
使用chrome driver和chrome浏览器并进入chrome的 toggle device mode 模式,就可以很好的模拟手机端,下面直接上代码
System.setProperty("webdriver.chrome.driver", config.getProperty("chromePath"));
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Apple iPhone 6");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver=new MobileChromeDriver(capabilities);
这里MobileChromeDriver是为了方便使用TouchActions,只需新建一个类继承自ChromeDriver并实现HasTouchScreen接口。
public class MobileChromeDriver extends ChromeDriver implements HasTouchScreen {
private RemoteTouchScreen touch;
public MobileChromeDriver(Capabilities capabilities) {
super(capabilities);
touch = new RemoteTouchScreen(getExecuteMethod());
}
public TouchScreen getTouch() {
return touch;
}
}
转载自:http://www.cnblogs.com/iamhp/p/6016194.html
http://www.cnblogs.com/g-song/p/5205972.html
System.setProperty("webdriver.chrome.driver", config.getProperty("chromePath"));
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Apple iPhone 6");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver=new MobileChromeDriver(capabilities);
这里MobileChromeDriver是为了方便使用TouchActions,只需新建一个类继承自ChromeDriver并实现HasTouchScreen接口。
public class MobileChromeDriver extends ChromeDriver implements HasTouchScreen {
private RemoteTouchScreen touch;
public MobileChromeDriver(Capabilities capabilities) {
super(capabilities);
touch = new RemoteTouchScreen(getExecuteMethod());
}
public TouchScreen getTouch() {
return touch;
}
}
转载自:http://www.cnblogs.com/iamhp/p/6016194.html
http://www.cnblogs.com/g-song/p/5205972.html
相关文章推荐
- android textview 设置超链接打开手机浏览器浏览链接数据
- android 小工具:pc 上用 curl 命令打开手机浏览器,浏览指定网址
- Selenium打开谷歌浏览器提示chromedriver.exe停止运行且浏览器显示请关闭开发者模式
- 通过手机浏览器打开APP或者跳转到下载页面.md
- 浏览器的浏览模式——兼容模式
- selenium如何通过快捷键关闭浏览器打开的新页签
- [IE编程] 打开/关闭IE8的光标浏览模式(Caret Browsing)
- Android WebView或手机浏览器打开连接问题解决办法总结
- 浏览器文档模式和浏览模式
- 在Nginx浏览器中打开目录浏览功能
- 设置双核浏览器的浏览模式<meta name=“renderer” content=“webkit|ie-comp|ie-stand”>
- windows资源管理器多标签打开 windows文件夹多标签浏览 浏览器tab页面一样浏览文件夹 clover win8 win10 报错 无响应问题怎么解决 clover卡死 clover怎么换皮肤
- python selenium 模拟手机浏览器
- 华硕手机打开调试模式
- 微信页面打开显示的样式与手机浏览器打开显示的样式不一样
- 如何使浏览器打开时,默认的文档模式就是标准模式
- 移动开发webapp开发常用meta设置(手机浏览器全屏模式 html5)
- android打开网页,使用手机浏览器
- 360极速模式可以浏览部分网页,其它浏览器不能浏览任何网页
- 关于用WebView或手机浏览器打开连接问题