2016-12-16 40 views
1

當我運行腳本時,網頁以土耳其語言打開。我想在英語語言轉換,嘗試下面的代碼使用Chrome的選項,但它是設置瀏覽器語言爲英語不網頁language.please幫助如何使用Selenium翻譯網頁語言ChromeDriver

static DesiredCapabilities setChromeCapabilities() 
    { 
     Map<String, Object> prefs = new HashMap<String, Object>(); 

     prefs.put("profile.default_content_settings.popups", 1); 
     prefs.put("download.default_directory", "C:\\dev\\tmpReport"); 

     ChromeOptions options = new ChromeOptions(); 
     options.setExperimentalOption("prefs", prefs); 
     options.addArguments("chrome.switches","--disable-extensions"); 
     options.addArguments("--start-maximized"); 
     options.addArguments("--lang=en"); **//tried adding this line of code** 

     DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
     capabilities.setCapability(ChromeOptions.CAPABILITY,options); 
     return capabilities; 
    } 

回答

0

你首先必須瞭解什麼使你的網頁上顯示土耳其或英語。 然後你就會知道如何解決這個問題。

例如,網頁可能會讀取用戶代理字符串中瀏覽器接受的語言。