我下载了ChromeDriver,默认浏览器语言是英语,我需要将其更改为西班牙语,但一直无法。
public WebDriver getDriver(String locale){
System.setProperty("webdriver.chrome.driver", "driver/chromedriver.exe");
return new ChromeDriver();
}
public void initializeSelenium() throws Exception{
driver = getDriver("en-us")
}
您可以通过添加 Chrome 来做到这一点命令行开关 http://peter.sh/experiments/chromium-command-line-switches/“——郎”。
基本上,您所需要的只是开始ChromeDriver
与Chrome选项 https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java#L105争论--lang=es
,详情参见API。
以下是关于如何使用 Selenium 以西班牙语启动 Chrome 的 C# 代码的工作示例。
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=es");
ChromeDriver driver = new ChromeDriver(options);
Java 代码应该几乎相同(未经测试)。请记住,此处的区域设置采用语言[-国家/地区] 形式,其中语言是 ISO-639 中的 2 个字母代码。
public WebDriver getDriver(String locale){
System.setProperty("webdriver.chrome.driver", "driver/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=" + locale);
return new ChromeDriver(options);
}
public void initializeSelenium() throws Exception{
driver = getDriver("es"); // two letters to represent the locale, or two letters + country
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)