我正在尝试使用 Selenium 测试我的网站,但我无法更改浏览器的语言。我尝试使用 Firefox,也更改了配置文件,但它不起作用。
很遗憾,因为我的很多内容都在语言方面发生了变化。
这是我的 Python 代码:
@classmethod
def setUpClass(cls):
super(SeleniumTestCase, cls).setUpClass()
options = Options()
options.add_argument('--lang=en')
cls.selenium = WebDriver(chrome_options=options)
所以通常我会更改语言但没有任何反应...
只是为了澄清。我已经检查了堆栈溢出,如果我发布这个问题,那真的是因为我尝试了我看到的大多数解决方案。
最佳答案
火狐 Java
将语言改为英文的Java代码:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "en-GB");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
driver = new FirefoxDriver(options);
ChromeJava
将语言改为英文的Java代码:
ChromeOptions options = new ChromeOptions();
options.addArguments("lang=en-GB");
driver = new ChromeDriver(options);
火狐 python
options = Options()
options.set_preference('intl.accept_languages', 'en-GB')
browser = webdriver.Firefox(options=options)
关于python - Selenium 更改语言浏览器 Chrome/Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33016300/