环境:Mac OS X 10.8.3,Ruby 2.0.0p0,selenium-webdriver 2.32.1,ChromeDriver 26.0.1383.0.
我想更改默认的浏览器语言.我正在测试网站是否正确检测到浏览器语言并以该语言显示页面.
我能够将Firefox语言设置为德语:
require "selenium-webdriver" profile = Selenium::WebDriver::Firefox::Profile.new profile["intl.accept_languages"] = "de" caps = Selenium::WebDriver::Remote::Capabilities.firefox(firefox_profile: profile) caps.platform = "Linux" caps.version = 20 driver = Selenium::WebDriver.for( :remote,url: "http://USERNAME:ACCESS-KEY@ondemand.saucelabs.com:80/wd/hub",desired_capabilities: caps) driver.navigate.to "http://sandBox.translatewiki.net/"
我想使用Chrome(和其他浏览器,如果可能的话)做同样的事情.
我尝试了几种在Chrome中用德语打开页面的东西,但每次页面都以英文显示,而不是用德语显示.
require "selenium-webdriver" profile = Selenium::WebDriver::Chrome::Profile.new profile["intl.accept_languages"] = "de" caps = Selenium::WebDriver::Remote::Capabilities.chrome(firefox_profile: profile) caps.platform = "Linux" caps.version = "" driver = Selenium::WebDriver.for( :remote,desired_capabilities: caps) driver.navigate.to "http://sandBox.translatewiki.net/"
如果我将firefox_profile:profile更改为profile:profile或chrome_profile:profile,则每次都会以英语(而不是德语)打开页面.
据我所知,在API docs中,仅支持:firefox_profile.
我能够在local machine上完成,但在使用Sauce Labs时却没有.
解决方法
这应该工作:
require "selenium-webdriver" profile = Selenium::WebDriver::Chrome::Profile.new profile["intl.accept_languages"] = "de" caps = Selenium::WebDriver::Remote::Capabilities.chrome( platform: "Linux",version: "",'chrome.profile' => profile.as_json['zip'] ) Selenium::WebDriver.for(:remote,url: "http://...@ondemand.saucelabs.com:80/wd/hub",desired_capabilities: caps )