I'm making a webscraping program, and in the same page I need to download multiple files.
But when I try to download the second file it pops up a message to allow multiple downloads.
I have already tried something like:
driver.SetPreference "download.default_directory", "C:\PDF_folder\"
driver.SetPreference "download.directory_upgrade", True
driver.SetPreference "download.prompt_for_download", False
But the allow window still appears. How can I solve that?
To allow to download multiple files you need to add the following preference:
driver.SetPreference "profile.default_content_setting_values.automatic_downloads": 1
Related
How do i set default upload path with selinium and chrome. eg going to a webpage, and upload. this opens a fileexploere, but it always opens c:\users[me]
I want to be able to set anoter default path.
i have seen this to set download path
driver.SetPreference "download.default_directory", "c:\temp"
and i tried to alter it
driver.SetPreference "upload.default_directory", "c:\temp"
but it dosnt work.
Chrome Version 102.0.5005.115 - win10
Found it
from this helpfull link
Where can I find a list of all available ChromeOption arguments?
theres a link to "List of preferences:"
in here i found
selectfile.last_directory
So i set
driver.SetPreference "selectfile.last_directory", "c:\temp" or what you want
I read through a ton of answers to this query of mine but couldn't find anything specific. Hence asking here
Here's the scenario, On a webpage, when I click a download button, it downloads a PDF file correctly, On the browser, I have set the Firefox preferences to save the file rather than open in preview.
However, when I run my selenium/Python script, the download keeps opening in the preview, there are other PDF downloads on the page and they work fine. Upon inspecting both the download buttons, the only difference I see is the one that does not download has a relative URL in its href value.
I am also using the following firefox options settings in my script, but with no help. Please guide me in the right direction. Thanks in advance!
**************************
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", 'Path to Save The file')
fp.set_preference("pdfjs.enabledCache.state", False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf")
fp.set_preference("pdfjs.disabled", "true")
# disable Adobe Acrobat PDF preview plugin
fp.set_preference("plugin.scan.plid.all", "false")
fp.set_preference("plugin.scan.Acrobat", "99.0")
self.driver = webdriver.Firefox(firefox_profile=fp,executable_path="path to my geckodriver")
self.driver.get("url")
I had the same problem - setting to disable pdfjs only worked when clicked manually on about:config page. Turned out that what seems to have solved the issue was (Firefox 60.6.1ESR):
profile.setPreference("pdfjs.disabled", true);
profile.setPreference("pdfjs.enabledCache.state", false); // <= THIS
Using Win7, Office2010, Chrome 58, and Selenium 2.0.9, I'm automating the downloading of a number of files from a few websites (NB, I actually need the files and the sites are not mine - I'm not testing my own site), and I'd like to control where the files end up being downloaded.
I have looked at quite a number of search results and everything I've found has led me to the following versions of code, each Driver.SetPreference variation has been tested independently and none of them work.
Private Sub DownloadDirTest()
Dim Driver As Selenium.ChromeDriver
Set Driver = New Selenium.ChromeDriver
Driver.SetPreference "browser.download.dir", "\\server\share\my\long\path"
Driver.SetPreference "browser.download.dir", "\\\\server\\share\\my\\long\path"
'after mapping Y: to "\\server\share\my\long\path" in Windows Explorer
Driver.SetPreference "browser.default_directory", "Y:\"
Driver.SetPreference "browser.download.dir", "c:\"
Driver.SetPreference "browser.default_directory", "c:\"
Driver.Start "Chrome", "http://google.com"
Driver.Close
End Sub
As can been seen here:
Most of the references I've seen are for Python, Java or Ruby, and they all make reference to something like:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
There doesn't seem to be any equivalent ChromeOptions available to VBA.
1) Does anyone know the actual property name to correctly set the download directory?
2) I'm not particularly wedded to Chrome, though it seems to be faster than IEDriver (in my initial testing), and I can't get the current Firefox driver to work. If someone has pointers to how to reliably set the DL directory in either of the other browsers (and a link to an updated Firefox driver - I haven't been able to find it via half-hearted searching), I'm open to using those.
The preferences from your example are specific to Firefox. You need to set the ones specific to Chrome to change the download directory:
Dim driver As New ChromeDriver
driver.SetPreference "download.default_directory", "c:\temp"
driver.SetPreference "download.directory_upgrade", True
driver.SetPreference "download.prompt_for_download", False
driver.SetPreference "safebrowsing.enabled", True
driver.SetPreference "plugins.plugins_disabled", Array("Chrome PDF Viewer")
driver.Get "http://google.com"
driver.Quit
I have an app that's designed to still be functional when JavaScript is disabled, so I wanted to write some specs that covered those cases.
I'm using Selenium (Firefox) with Capybara and I'm registering an new driver with JavaScript disabled (via Selenium's javascript.enabled property)
# spec/rails_helper.rb
Capybara.configure do |config|
config.ignore_hidden_elements = true
config.default_driver = :selenium
end
Capybara.register_driver :disable_js do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile["javascript.enabled"] = false
Capybara::Selenium::Driver.new(app, profile: profile)
end
# spec/features/siging_in_spec.rb
context "JavaScript disabled", driver: :disable_js do
it "user can still sign in" do
# ...
# ...
end
end
The feature specs are failing to actually disable JavaScript. When the browser window pops up during testing and I pause it with binding.pry, I can definitely click around on items I know require JavaScript and see them working.
Side note: If I actually go to my Firefox settings and disable JavaScript, the test passes. So it appears it's inheriting whatever configuration I set in my browser, and not actually using the configuration specified when registering the driver.
Is this the correct approach here, or is there something I missed?
Thanks!
It's not possible to change the javascript.enabled setting when registering the driver because selenium freezes it at true - https://github.com/SeleniumHQ/selenium/blob/master/javascript/firefox-driver/webdriver.json#L35 - This was done because of issues with trying to use selenium and firefox with JS disabled https://github.com/SeleniumHQ/selenium/issues/635 - and is unlikely to be changed. Can you just run those specific tests with the rack_test driver? or does it not provide enough functionality?
Unfortunately, setting profile["javascript.enabled"] = false no longer works.
An alternative is to install a Firefox addon that disables JavaScript. This worked for me with Firefox 45 ESR, selenium-webdriver (2.53.4), and capybara (2.8.1):
profile.add_extension(File.expand_path('../quickjava-2.1.0-fx.xpi', __FILE__))
# Configure the extension to disable JavaScript by default.
profile['extensions.thatoneguydotnet.QuickJava.startupStatus.JavaScript'] = 2
# Disable loading the extension's first-run tab.
profile['extensions.thatoneguydotnet.QuickJava.curVersion'] = '2.1.0'
I evaluated a few different addons, including NoScript and QuickJs, but decided to find a very simple addon that could disable JavaScript by default—QuickJava did the trick. You can download the XPI file here (use Firefox, right click and Save As instead of installing directly): https://addons.mozilla.org/en-US/firefox/addon/quickjava/versions/
You can also see all of the addon's pref settings in the source.
While running WebDriver automation scripts I came across a situation where it is trying to open a page which contain one segment with live camera (Made with Java applet). Once script reaches to this page - a Security Warning alert (with allow and not allow) shows up and blocks the execution process. Is this something that anyone faced before - actually I am looking for an option to block this security warning to get displayed on the page.
A popup is coming where i want to click on the "Allow". How to move the focus to the new popup window and click on Allow.
Can anyone please help me for the above problem?
I was having problems accepting the java applet "Allow"
My solution was to create a firefox profile that had the settings to always activate the plugin:
FirefoxProfile fp = new FirefoxProfile();
fp.setAcceptUntrustedCertificates( true );
fp.setPreference( "security.enable_java", true );
fp.setPreference( "plugin.state.java", 2 );
WebDriver d = new FirefoxDriver( fp );
Where plugin.state.java:
plugin.state.java = 0 --> never activate
plugin.state.java = 1 --> ask to activate
plugin.state.java = 2 --> always activate
This might get you closer...
Selenium uses a different firefox profile because Java was inactive for me and I did not have my firebug plugin in the Firefox browser Selenium launched. I would have to open another Firefox to use Firebug.
I found my default Firefox profile by searching %appdata% in the start menu then clicking on Roaming/ Mozilla/ Firefox/ Profile/ and then it gave my default profile name.
You can also open the firefox help menu (? logo) & click troubleshoot info... click Show Profile Folder
I then configured selenium to use my default profile so Java was enabled and Firebug was available in the browser Selenium launched:
Make sure that you use "/" in selenium even though it may use "\" in the windows path location
fp = webdriver.FirefoxProfile('C:/Users/xxx/AppData/Roaming/Mozilla/Firefox/Profiles/41s7nq9o.default')
driver = webdriver.Firefox(fp)
driver.get('www.stackoverflow.com')
where 41s7nq9o.default is the name of your default profile