当前位置:   article > 正文

safari android 模拟,Selenium模拟移动设备(iOS,Android,etc)浏览器

安卓模拟safari

package com.netease.demo;

import java.io.File;

import java.io.IOException;

import java.util.Arrays;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriverService;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

public class MobileBrowser {

public static void main(String[] args) throws Exception {

// 启动Chromedriver Server

ChromeDriverService chromeServer = new ChromeDriverService.Builder().usingDriverExecutable(new File("res/chromedriver_for_mac")).usingAnyFreePort().build();

try {

chromeServer.start();

} catch (IOException e) {

e.printStackTrace();

}

// 以iPad模式启动Chrome,并访问网易门户

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

capabilities.setCapability("chrome.switches", Arrays.asList("--user-agent=\"Mozilla/5.0 (iPad; U; CPU OS 3_2_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B500 Safari/531.21.10\""));

WebDriver wb = new RemoteWebDriver(chromeServer.getUrl(), capabilities);

wb.get("http://www.163.com");

Thread.sleep(2500);

wb.quit();

chromeServer.stop();

}

}

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号