使用Selenium WebDriver启用/禁用javascript [英] Enable/disable javascript using Selenium WebDriver
问题描述
出于某种原因,我必须禁用Firefox的javascript(手动,我们可以按照
For some reason, I've to disable javascript for Firefox (Manually, we do by following steps mentioned http://support.mozilla.org/en-US/kb/javascript-settings-for-interactive-web-pages#w_enabling-and-disabling-javascript). How can this be achieved by Selenium WebDriver using Ruby?
推荐答案
是的,有可能.但是是另一种方式.您首先需要查看链接
Yes, It is possible. But a different way. You first need to look into the link
-
一旦您访问链接,请尝试以下代码:
Once you would visit the link,try the below code :
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>
一旦通过以上代码打开浏览器窗口,然后从 Edit-> Preferences-> content 中检查 Preferences ,那么您会看到未选中 启用JavaScript: 选项.
Once your browser window will be opened up through the above code,then check the Preferences from Edit->Preferences->content,then you would see that Enable JavaScript: option is unchecked.
这篇关于使用Selenium WebDriver启用/禁用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!