出于某种原因,我要为Firefox禁用javascript(手动,我们按照http://support.mozilla.org/en-US/kb/javascript-settings-for-interactive-web-pages#w_enabling-and-disabling-javascript提到的步骤进行操作)。如何通过Selenium WebDriver使用Ruby实现这一目标?
答案 0 :(得分:4)
是的,有可能。但是方式不同。您首先需要查看链接
一旦您访问该链接,请尝试以下代码:
require 'selenium-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile["javascript.enabled"] = false
driver = Selenium::WebDriver.for(:firefox, :profile => profile)
profile
# => #<Selenium::WebDriver::Firefox::Profile:0x89c7568
# @additional_prefs=
# {"javascript.enabled"=>false, "webdriver_firefox_port"=>7055},
# @extensions=
# {:webdriver=>
# #<Selenium::WebDriver::Firefox::Extension:0x89c6488 # !> previous definition of proxy= was here
# @path=
# "/home/kirti/.rvm/gems/ruby-2.0.0-p0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/extension/webdriver.xpi",
# @should_reap_root=true>},
# @load_no_focus_lib=false,
# @model=nil,
# @native_events=false,
# @secure_ssl=false,
# @untrusted_issuer=true>
通过上述代码打开浏览器窗口后,从 编辑 - &gt;偏好设置&gt;内容 偏好设置 >,然后您会看到 启用JavaScript: 选项未选中。