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

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.

Related

Selenium WebDriver file upload issue on ChromeDriver

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!

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

Handle Windows Open File dialog in Selenium

How can handle Window Open File dialog (set file path and import) using javascript (or some other way) in Selenium ?
If you are trying to upload a file, and the page in question uses the standard upload mechanisms provided by HTML, you can do this directly with Selenium itself. The standard HTML mechanism is with an <input type=‘file’> element. Once you’ve found that file upload element on the page, you can use element.sendKeys(“full/path/and/file/name/here”);. This is documented in Step 10 of the algorithm for the Element Send Keys command of the W3C WebDriver Specification, and is used in several file upload tests in the Selenium project’s test code (example).
//set file path
driver.findelelment(By.Xpath("//input[contains(#type,'file')]")).SendKeys(UploadFilePath);

automate image upload from windows explore with selenium and AutoIT

I have to automate a scenario like a upload an image from windows explorer to TinyMCE component using Selenium. Since Selenium does not support OS control, I used AutoIt to upload the image.
AutiIt sets the image path to "File name" and seems like it clicks on 'Open' button as well. But the image is not loading to my "source" field.
Here is my Selenium command:
Runtime.getRuntime().exec("C:/XXXXX/src/test/resources/uploadImage.exe");
// Path of the AutoIT script file
AutoIT script:
WinActivate("Open")
Send("C:\LCNGProjects\Screenshots\Images\GifImage1.gif")
Sleep(5000)
Send("{ENTER}")
Refer the attached screenshot
Not sure if I have got the questions correct, Did you compile the script.
Can you please go through link below for script compilation and step by step info how to upload a file.
https://www.guru99.com/use-autoit-selenium.html
You do not need to use AutoIt. Auto will make your script dependable on windows machine only.
Instead of it find element using locator(i.e. xpath) of upload button which is having tag as type="file". Now pass this simple sendKeys with absolute path of your image in your machine like below:-
button2.sendKeys("C:\\UsersDesktop\\logo\\Summit-Logo-900px.png");
Or use
System.getProperty("user.dir"));
Append the path of file exluding your project path and filename inside your project
Example :-
button.sendKeys(System.getProperty("user.dir")+"\\logo\\Summit-Logo-900px.png");
below link contains more option to upload file like below :-
Using SendKeys command.
Using AutoIt scripting.
Using Jacob com interface.
http://www.techbeamers.com/handle-file-upload-selenium-webdriver/#h3
Hope it will help you :)
I'm not going to add full source code here. You can call the AutoIT script using this command inside your test case.
// Call to AutoIT script to upload the image
Runtime.getRuntime().exec("C:\\xxxxx\\src\\test\\resources\\uploadImage.exe");
AutoIT Scrip
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1","C:\xxxx\Images\jpgImage")
ControlClick("Open","","Button1")
For more information refer the following link
https://www.guru99.com/use-autoit-selenium.html

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