I am trying to upload a file using Sahi. It is the usual upload file step, click on the 'Upload File', then popup window opens for user to select the file, then click open.
Sahi doesn't recognise the popup window. I tried to use the _setFile, doesn't seem to do anything. Could any one please help?
_setFile(_file("uploadForm:j_id_1d_input"), "\\scripts\\II\\image\\png.png");
Many thanks
You are using invalid path ,
below URL path can help you.....
_setFile2(_file("modelFile"), "C:\\users\\sfatimi\\Desktop\\excel-model-4.1.jar")
You can use both , _setfile2 and _setfile
if you some validations implemented on uploading use _setfile2
Related
I'm having this problem:
At the website I'm trying to test with webdriverio, it has this functionality:
You click a button to upload a file (a window opens to choose your local file)
You select your file and click Accept.
When you click Accept, a modal opens and gives you a progress bar and also some mandatory inputs to continue the process and the test.
In other cases, uploading the file with this:
https://webdriver.io/blog/2019/06/25/file-upload/
it works fine!
But in this case, I need to open the modal after you click Accept at the window (anyway I'm not really clicking on Accept button at the locals file window, so probably this should be solve before, but I don't know how to do it)… and its not happening.
Thanks for the help!
Good morning. I have a web page control with selenium. However, when I click the button of the site, a pop-up screen appears and I want to test that the file attachment is saved by pressing the file attachment button in it. Can you control selenium with two windows (parent, child-popup) going up and down?
I guess you want to interact with file upload dialog which is native window via selenium. That is not possible. However you can select file to upload using sendKeys without the dialog being opened.
Something like that
fileInput.sendKeys("/path/to/local/file");
]1
There are many examples on what to do with file upload, however I could not find anything in selecting folder. Any ideas how to handle this ?
UPDATE:
I have tried 3 different ways but none worked :
the first is using sendkeys(). This does not work because there is no input field. This dialog opens when you click a button.
The second is using AutoIt, which is used in the uploading files dialog. It causes an error when i use it because I am not uploading a file but just selecting a folder.
the third is robot, where I copy the path I want to the clipboard and try to paste it with robot. It did not work for me.
Update 2:
If you open chrome://extensions/ on chrome browser and tick developer mode you will see a load unpacked extensions buttons. This is the button that when you click you get this windows dialog:
There are different ways by which you can handle File Upload :
Way 1:
WebElement fileInput = driver.findElement(By.name("uploadfile"));
fileInput.sendKeys("C:/path/to/file.jpg");
Way 2:
By using Robot Class API:
driver.findElement(By.By.name("uploadfile")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_KP_DOWN);
r.keyRelease(KeyEvent.VK_KP_DOWN);
r.keyPress(KeyEvent.VK_KP_RIGHT);
r.keyRelease(KeyEvent.VK_KP_RIGHT);
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
Hope it will help you
Selenium support is for Web browser and not for windows dialogs.
the only option for you is to write automation using coded UI or Autoit.
Selenium only works on Web browser, You can use AutoIT but I see you already tried it. In that case I would suggest you to use Sikuli.
I have a webpage where I click on a button and an open dialog it's opened and I should select the file to upload. After that, a pop up is displayed saying OK or KO.
I'm able to upload files when the there are files types. But in this case, the element where I click it's:
<
button type="button" read-file="_.partial(submitLang, selectedLang)" id="import-lang" class="btn btn-default"><
/button>
For the rest of the application, I use this and it works:
WebElement element = getPage().findElementById(id);
element.sendKeys(absoluteFile);
But for button types and button tag it doesn't work.
How can I do it? The tests are running on a Linux machine
Thanks a lot!
More info!!
Hi all,
The whole process is: (see image at http://imageshack.com/a/img540/6237/JoTQng.png)
Click on Import button
A dialog is opened and I select a .json file and click Open
An alert is displayed saying "Text properties have been updated".
We are using angular for the frontend and all are REST calls.
We don't have any "file=type". All three are buttons. You can found more code at
http://imageshack.com/a/img633/7299/BQhP7o.png
For a file upload with selenium, you need to find an input tag with the type "file".
Have a look at your HTML and search for it.
When you found it, the rest is pretty straightforward:
Let's say this input-element has id="import"
driver.findElement(By.id("import")).sendKeys(absoluteFile);
If you run into problems, please post more of your HTML, then I can have a look at it.
In my case, clicking on the button made an element appear in the HTML code, I assume due to javascript.
I clicked on the element (which both opens a file upload window and adds the to the HTML), and immediately after send the keys to the input element.
This creates the problem of having to close the newly opened file upload window, however this is not a problem when using --headless mode on google chrome.
I do not have a solution to close this window if you are not in headless mode for your chosen browser.
I can not close the finder window that has taken the desired file that I wanted to upload with selenium webdriver.
Here is my code:
WebElement changeFle=driver.findElement(By.id("tradeDocFile"));
changeFle.click();
changeFle.sendKeys("C:\\Users\\ranjan\\Downloads\\Selenium Program_Xpath_CssSelectors.pdf");
driver.findElement(By.id("btnSaveTradeDocument")).sendKeys(Keys.ENTER);
After it gets executed file is being uploaded but file upload "Open" window is not being closed.
WebElement changeFle=driver.findElement(By.id("tradeDocFile"));
// no need to click on upload button
changeFle.click();
changeFle.sendKeys("C:\Users\ranjan\Downloads\Selenium Program_Xpath_CssSelectors.pdf");
driver.findElement(By.id("btnSaveTradeDocument")).sendKeys(Keys.ENTER);
I didn't find a direct way to close it, because this window is kind of system File manager window that is opened by OS (Windows or MacOS, other). So the only way I found to do it is:
press the open file button
send file to needed input
close driver using driver.close()
I understand, that it is not the super direct solution that is desired, but I built my flow another way, e.g:
downloaded the needed CSV file
updated the file
uploaded file back
closed driver.
opened a driver again
download the second file
updated the second file
closed a driver
...
1) If you want to upload by sending the file path then no need to click on Browse(Or whatever the name of the button)
2) If you want to upload using the dialog box then use Auto IT or Sikuli
Thanks