Note that there are some explanatory texts on larger screens.

plurals
  1. POSelenium 2 chrome driver preferences java equivalent to RubyBindings
    primarykey
    data
    text
    <p>I've been looking for a way to set the driver preferences for chrome driver using java for the past two days with no luck.</p> <p>I have however found a solution in ruby VIA RubyBindings and would like to know if there is a java equivalent line I can use for this.</p> <p>The ruby code is the following:</p> <pre><code>profile = Selenium::WebDriver::Chrome::Profile.new profile['download.prompt_for_download'] = false profile['download.default_directory'] = "/path/to/dir" driver = Selenium::WebDriver.for :chrome, :profile =&gt; profile </code></pre> <p>While searching I found that chrome does not have a profiler I could use like the FirefoxProfile class, so I started using the DesireCapabilities class instead. After further investigation into this problem I found that I could set the "switches" and "prefs" VIA capabilities.setCapabilitiy and ended up with the following:</p> <pre><code>Map&lt;String, String&gt; prefs = new Hashtable&lt;String, String&gt;(); prefs.put("download.prompt_for_download", "false"); prefs.put("download.default_directory", "/path/to/dir"); prefs.put("download.extensions_to_open", "pdf"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.prefs", prefs); dr = new ChromeDriver(capabilities); </code></pre> <p>However I was not able to get this working, the default download directory was never changed to the specified directory once started. I am unsure if there is a problem with how I am trying to set this capability or if the problem lies elsewhere.</p> <p>In the end I eventually used the solution proposed here:<br> <a href="http://dkage.wordpress.com/2012/03/10/mid-air-trick-make-selenium-download-files/" rel="nofollow">http://dkage.wordpress.com/2012/03/10/mid-air-trick-make-selenium-download-files/</a></p> <p>but I would like to know if it is possible to do this more cleanly but just setting the preferences directly instead of using the UI</p> <p>Any help is appreciated, Thanks!</p> <p><strong>Update:</strong><br> Surprisingly after updating Selenium 2 to version 2.24.1 (and to windows chrome 22), the code above with the Maps work as expected, the only problem now is that they deprecated the the use of the constructor ChromeDriver(DesiredCapabilities capabilities), and instead recommend I use the ChromeOptions class, which I cannot get working for the above scenario.</p> <p>Below is the wiki page explaining the use of both ChromeOptions and DesiredCapabilities: <a href="http://code.google.com/p/chromedriver/wiki/CapabilitiesAndSwitches" rel="nofollow">http://code.google.com/p/chromedriver/wiki/CapabilitiesAndSwitches</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload