python - Selenium 更改语言浏览器 Chrome/Firefox

标签 python selenium testing

我正在尝试使用 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/

相关文章:

python - PyRo 可以在生产中扩展吗?

python - 将标题行写入 csv python

angular - Angular Testing async+whenStable 和 fakeAsync+tick 有什么区别?

django - Django 中的单元测试 CRUD 功能

javascript - Protractor:如何使用 href 子字符串或 span 子字符串单击元素?

unit-testing - Erlang - Eunit 设置函数不运行

python - 在Python中删除EXIF数据?

python - 颜色可变但 Alpha 独立

python - 将现有 csv 文件中的每一列复制并粘贴到新的 csv 文件中

python - 显式等待在基于 Angular 的 PayPal 沙箱上不起作用