download a file using selenium - 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?

Related

Selenium File Upload Not Working in Azure Pipeline/ VM Machine

Hi I am Trying Achieve File upload Scenario My Test cases using selenium
Element I am Doing Actions On:-
<input _ngcontent-swn-c63="" type="file" id="undefined" multiple="" accept=".gif, .xlsm, .zip, .xls,.xlsx, .pdf, .ppt, .pptx, .doc, .docx, .jpeg, .jpg, .png, .csv, .txt">
Selenium Script I am Using :-
WebElement UploadElement=(new WebDriverWait(driver, BaseInitializer.defaultwaitTime)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[#type='file' and #id='undefined']")));
((JavascriptExecutor)driver).executeScript("arguments[0].style.display = 'block';", UploadElement);
UploadElement.sendKeys(newname.getAbsolutePath());
While the above piece of code is working in My Local Machine(Chrome browser). Same script is not working while running the code in Azures Pipeline. The File is not getting reflected in Upload Element. What may be the issue? Or I am missing something?

Selenium IDE - Upload file into field

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>

How to get html content remotely and open locally

I want to get the content remotely for a html page and open locally in the webview. But I want this html to have access to the Ti namespace, so it implies that the html must be running locally.
Have tried to create the webview passing the content as the "html" parameter, but Ti namespace doesnt work that way.
Then, I tried to write the content to a html file on Ti.Filesystem.applicationDataDirectory. The page opens OK, but the Ti namespace doesnt work on the html either.
Finaly, I created a html file in assets folder on the project and when I get the html code I try to write on it so I could open using 'url' : '/myfile.html'. But when I try to write it gives java.io.IOException: read only
How can I achieve this? Again: I'm trying to get a html content remotely and run locally so I can have access to Ti namespace.
Thanks
I messed up during my testings. Downloading the html and then opening the webview passing the html code to "html" parameter on the webview works just fine. The fireEvent works that way inside the html.
It was not working because it was other problem not related that I fixed.

Create object from dll then calling a method

I am trying to call some methods from a dll library. I have found some examples in JavaScript and c++ . I don't know how to use c++ so let me show you what I have worked out for the JavaScript example:
<html>
<head>
<title>Palm Pad</title>
</HEAD>
<script type="text/javascript" language="JavaScript1.2">
if(window.ActiveXObject) {
//var ActiveHomeObj = new ActiveXObject("X10.ActiveHome");
} else {
alert("This script was design to work with Internet Explore 5 and up");
}
function getUSCode(Button1,OnOff)
{
ActiveHomeObj.SendAction("sendplc","A1 on");
}
</script>
<body>
click here to see if method runs
<OBJECT ID="ActiveHomeObj" classid="CLSID:001000AF-2DEF-0208-10B6-DC5BA692C858" codebase="ahscript.dll" type="application/x-oleobject"></OBJECT>
</body>
</html>
as you can see this is a very simple html page with just one JavaScript function that gets executed when clicking on the link. The problem with this script is that it only works with internet explorer and when using it I get the warning.
If I use internet explorer and I enable the blocked content I am able to execute the SendAction method on the ahscript.dll library.
I will like to run this with other browsers as well so it will be nice if I can create a .bat file that would enable me to do the same thing. Or a vbs script. Or any other script...
if for some reason you know AutoIt here is what I have tried out with it:
AutoIt:
DllCall("ahscript.dll","none","SendAction","str","sendplc","str", "A1 on")
and
$o = ObjCreate("C:\Users\Virgilio\Desktop\x10\ahscript.dll")
$o.SendAction("sendplc","A1 on")
in vbs I have treid something similar.
How could I create an executable file that when executing it I can get the same result that if I where to open the html file in internet explorer then enable the warning and lastly executing the javascrip function?
Sorry, you're out of luck here.
First, ActiveXObject is specific to Internet Explorer. Firefox and Chrome do not support it. You can use special plugins for Firefox and Chrome that will enable an IE tab, but that is still IE.
In addition, ActiveX/COM is specific to Windows. You can use ActiveX/COM from Wine, but it is not natively supported by any other OS.

Javascript window.open(xxx, "download") creates a blank page while download prompt

When I run window.open(file, "download") with safari, it opens a blank page while download prompt and the blank page stays there. I notice firefox opens a blank tab but it's close when download starts. Is there another javascript command/function that will work so there's no blank page opened in Safari?
Why don't you use window.location = file instead?
Redirecting to the file leads to the same behavior as clicking on a link to that file: you get the download prompt, and the browser stays on the current page!
Call window.open like this (it works in all major browsers):
window.open(file, '_parent', 'download');