How to change the language of a WebDriver?

后端 未结 3 1801
野性不改
野性不改 2020-12-14 02:35

I want to execute my Selenium tests in different languages. Is it possible to change the language of an existing WebDriver at runtime or do I have to recreate the browser in

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 02:58

    You can also do it through about:config in firefox. But you need to use Actions to manipulate it.

    Below a java piece of code

        Actions act = new Actions(webDriver);          
    
        webDriver.get("about:config");
    
        // warning screen
        act.sendKeys(Keys.RETURN).perform();
    
        // Go directly to the list, don't use the search option, it's not fast enough
        act.sendKeys(Keys.TAB).perform();
    
        // Go to the intl.accept_languages option
        act.sendKeys("intl.accept_languages").sendKeys(Keys.RETURN).perform();
    
        // fill the alert with your parameters
        webDriver.switchTo().alert().sendKeys("fr, fr-fr, en-us, en");
        webDriver.switchTo().alert().accept();
    

提交回复
热议问题