Selenium IDE - Upload file into field - selenium

I'm creating a testing suite to automate some parts of data input on my web application. I have a page where I can click on a button to upload a document to the application. It looks something like this:
Once the Add New Attachment button is clicked, it opens the browser's file explorer to select a document to upload. I'm trying to replicate this within Selenium IDE.
Here is what it looks like as of now:
However, this part seems to fail. Does anyone know how to achieve a similar process using Selenium IDE? I'm on Chrome and Firefox.

If you get the
{"code":-32000,"message":"Not allowed"}
on Chrome, follow the steps below:
Window > More Tools > Extensions > Selenium IDE > Details
Then turn on the 'Allow access to file URLs' option.
I was having the same problem and this worked for me.

It is possible to upload the files using selenium IDE. It can be done as mentioned below.
|Command|Target|Value|
|type|target_location_path|location_of_the_file_in_your_system|
Example:
|type|id=ConsignmentCustomerInvoiceFilename|C:\Users\abc\Desktop\img1.jpg|
You can identify the "target_location_path" by manually uploading the file and then finding the xpath of the uploaded file in the web app.
Please refer below screenshot to get a better understanding.
SeleniumIDE_uploadfile
You can add the system path to the IDE test by using the below code.
<tr>
<td>storeEval</td>
<td>Preferences.getString(TestSuite.TEST_SUITE_DIRECTORY_PREF);</td>
<td>testSuiteFolder</td>
</tr>
<tr>
<td>type</td>
<td>id=QuestionUpload_file</td>
<td>${testSuiteFolder}/resources/question_upload.csv</td>
</tr>

Related

Running Chrome from PortableApps with Selenium WebDriver fails

I've got C# Selenium project and want to run portable Chrome downloaded from here.
My chromeOptions are:
chromeOptions.BinaryLocation = Path.GetFullPath("C:\", "tests.browsers", "windows", "chrome", "GoogleChromePortable.exe"));
chromeOptions.AddArgument("--enable-logging");
chromeOptions.AddArgument("--v=1");
chromeOptions.AddExtension(Path.Combine("path", "to", "kontur-plugin.crx"));
But when I run the test, Chrome opens and shows this:
(notifications say "Failed to login %EXTENSIONNAME%, click to load it once again)
chrome_debug.log contains no errors.
What am I doing wrong? How can I figure out what is the problem with?
this might help you - Stackoverflow post
also, your CRX file should add as a file, not just the path.

jQuery 3.3.1 file upload freeze in Safari 12.1.2 and higher

I'm trying to upload a file using jQuery 3.3.1 in Safari 12.1.2 and it allows me to browse and select the file that needs to be uploaded. But when I try to upload the selected file. It does nothing. No error message is displayed, at least in the browser console. This is working fine in Safari versions below 12.1.2, Chrome and Firefox. Can some one please let me know a clue to at least start troubleshooting this issue. (I also tried to debug the code but it ended up in jQuery-3.3.1.min.js and terminates.)
Found the change required to fix the issue. Option "forceIframeTransport" In the code snippet that refers to the fileupload function in jdeQuery-File-Upload has been set to "true" in my code. (As per the jQuery-File-Upload doc this value is set to false by default) How ever for a unknown reason file upload fails in Safari 12.1.2 and above when this value is set to true. So simple the fix in my case is setting "forceIframeTransport" to "false" as shown in below code snippet. (please note that it's not required to have cross cite file uploads which is affected by this option in my application)
$('.assetupload').fileupload({
**forceIframeTransport : false**,
add : function(e, data) {
.......
.......
});

Cannot Download PDF's Using Selenium/Python 3.x, But It works When I do it Manually

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

download a file using selenium

I have a website that is downloading a file when I press a link.
The source code of the link is:
<a onclick="downloadTheCsv(); return false;" id="ddlkkjs" class="buttonlink" href="javascript:__doPostBack('ctl01$linkebr2','')">Download Comma Separated File</a>
I am using RSelenium but when executing
remDr$executeScript("downloadTheCsv(); return false;")
the file is not downloaded...
However in chrome if I call downloadTheCsv() in the console it works.
Any ideas?

How to deal with Java warning popup?

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