加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – Chrome的自定义配置文件

发布时间:2020-12-17 04:14:16 所属栏目:百科 来源:网络整理
导读:环境: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 =
环境: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
)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读