赞
踩
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();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。