Created
August 25, 2013 05:33
-
-
Save masayuki5160/6332190 to your computer and use it in GitHub Desktop.
SeleniumでUAを指定してテストをしたいとき
参考:http://blog.asial.co.jp/1180、http://design-ambience.com/wordpress/?p=114、https://code.google.com/p/selenium/wiki/FirefoxDriver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.firefox.FirefoxProfile; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
public class Test { | |
public static void main(String[] args) { | |
//UAの設定を行う | |
FirefoxProfile profile = new FirefoxProfile(); | |
profile.setPreference("general.useragent.override", "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3"); | |
//UAを指定する場合はこっち、指定しないときは引数なし | |
RemoteWebDriver driver = new FirefoxDriver(profile); | |
// RemoteWebDriver driver = new FirefoxDriver(); | |
driver.get("http://zozo.jp/"); | |
sleep(1000); | |
//driver.quit(); | |
} | |
private static void sleep(int microtime) { | |
try { | |
Thread.sleep(microtime); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment