Enable / disable javascript using Selenium WebDriver

For some reason I have to disable javascript for Firefox (in manual mode we do the 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 with Selenium WebDriver using Ruby?

+6
source share
1 answer

Yes it is possible. But in a different way. First you need to look at the link

As soon as you follow the link, try the code below:

 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> 

As soon as your browser window opens through the above code, then check the settings from Edit-> Settings-> content , then you will see that Enable JavaScript: is not checked.

Enable JavaScript:

+4
source

Source: https://habr.com/ru/post/947854/


All Articles