Selenium WebDriver file upload issue on ChromeDriver - selenium

On GitLab while submitting an merge request, Im trying to attach a file from local driver,when I click "Attach a file" button and when I select the file from local it will show up on the text area input.
When I try to automate through selenium, after selecting the file from local drive, I'm unable to attach the file as the input text area doesn't directly have local driver path of where the file is stored.
i.e. : the input text area should contain something like "C\test.PNG" but it has "![test](/uploads/2536727737372/test.PNG"
Is there a way we can still automate this scenario?

You can element.sendkeys the file path directly to "Attach a file" button element, and the file should get uploaded.
WebElement attachAFile = driver.findElement(By.id("attachAFile"));
attachAFile.sendKeys("C\\test.PNG");
No need of clicking the "Attach a file" button to upload the file!

Related

autoit +selanium on jenkins does not work

enter image description hereI have a selenium test implement for web application and implemented autoit to do a folder upload to my application. This folder upload initiates a chrome popup warning which has no title but 2 buttons "Upload" and "Cancel" (default selected). The folder upload is in the control of my application and has title for the popup window. So I could see controlfocus worked on upload folder popup even when my test was deployed on jenkins. But it does not click on the Chrome popup warning
#include <WinAPIFiles.au3>
ControlFocus("Select Folder to Upload","","Edit1")
ControlSetText("Select Folder to Upload","","Edit1","<Myfolder Path>")
sleep(4000)
ControlClick("Select Folder to Upload","","Button1")
sleep(4000)
;this is for the popup warning from chrome
ControlFocus("[CLASS:Edit; INSTANCE:1]","","Edit1")
Send("{LEFT}") <===== this and below does not ever work on jenkins but works on local
execution
Send("{ENTER}")
;sleep(10000)
exit(0)
my selenium code has
String filepath = ".\\uploadfile.bat";
Process p1 = Runtime.getRuntime().exec( filepath );
uploadfile.bat is ....
START /wait c:\AutoIT\uploadfld.exe
As first step run yours AutoIt script, and just after that click the HTML element using selenium.
Do not try to run AutoIt script after clicking the HTML element in selenium, as this stops your selenium because browser waits for file selection.
And as I said in one other cases (question which I answer some time ago), there should be other possibilities to do that without AutoIt, even without invoking the pop up window.

how to handle file upload case in ubuntu machine using selenium with java

driver.findElement(By.xpath("//div[#class='invoiceUploadButton mat-elevation-z1 fileBrowseContainer']")).click();
with this i am able to click on choose file button to upload file.But after it i have a window pop-up to upload respective file. How to upload my file here? It works only in windows machine.
HTML Dom reference
<div class="invoiceUploadButton mat-elevation-z1 fileBrowseContainer">
<span>Choose File</span>
</div>
Try using the sendKeys method to provide the file path and then hit the Upload or Ok button.
addFile.sendKeys("D:\Big Data on AWS\Images\caps.jpeg");
driver.findElement(//Upload button).click();

upload file for SELENIUM IDE

I want to upload a file to automate a process with Selenium IDE from chrome, I already gave the permissions to the extension, however I get the following error yet.
The way I'm loading the file is as follows:
Command: type
id= txtFile
Value: C:\fakepath\factura.xls
Failed:
Unable to upload files due to cross origin frames in the page
https://i.stack.imgur.com/LNUqH.png
ist because of the Fakepath
You need to insert the direct path.
You can look it up by making a left click in the Explorer on the document.
The path should be visible now

How to download the *.jar file from http:// seleniumhq.org using selenium WebDriver code?

Steps: open the Browser > enter URL http://seleniumhq.org >
Click Download tab > click Download version “2.46.0” link
It opens a dialog window. Click “Save File” button
Note: I have tried download *.xls file example code from URL: http://seleniumeasy.com/selenium-tutorials/how-to-download-a-file-with-webdriver it is working fine in my system. It automatically handling the dialog box and saving the file in destination location.
But the same code not working to download the *.jar file.
Could you please look into this one and help me to resolve this?
If you are downloading Selenium Standalone Server try this:
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive");
If downloading selenium java webdriver:
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
Here is a nice link for a detailed list of file format MIME type list: ClickME

How to enable prompting the user for download location in Safari using webdriver?

I found the following link
how to handle file downlaod for selenium webdriver for safari
where it is mentioned to use the following code:
dc.setCapability("safari.options.dataDir", "your folder path");
This code needs to give the path in advance.
What should I do if I want the option to prompt the user to input the file path everytime while downloading file?
My path can change for each and every file to be downloaded.