在Java中使用Selenium WebDriver更改用户代理 [英] Changing the user agent using selenium webdriver in Java
本文介绍了在Java中使用Selenium WebDriver更改用户代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何使用Java中的webdriver切换用户代理吗? 我在下面尝试过,但出现错误.
Can someone pls tell me how to switch the user agent using webdriver in Java? I tried below, but getting errors.
FirefoxProfile ffp = new FirefoxProfile();
ffp.setPreference("general.useragent.override",
"Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0");
WebDriver fd = new FirefoxDriver(ffp);
推荐答案
DesiredCapabilities 可以帮助您更改用户代理.
DesiredCapabilities would help you to change user agent.
您可以通过调用以下方法来实现:
You can achieve this by calling these methods:
-
setBrowserName(java.lang.String browserName)
-
setPlatform(Platform platform)
-
setVersion(java.lang.String version)
setBrowserName(java.lang.String browserName)
setPlatform(Platform platform)
setVersion(java.lang.String version)
或
-
static DesiredCapabilities chrome()
-
static DesiredCapabilities firefox()
-
static DesiredCapabilities iphone()
- ...
static DesiredCapabilities chrome()
static DesiredCapabilities firefox()
static DesiredCapabilities iphone()
- ...
更多此处.
这篇关于在Java中使用Selenium WebDriver更改用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文