Selenium Upload a file using button type and button tag instead of file - selenium

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.

Related

Uploading a file with webdriverio and open modal

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!

Capture objects which are pops up from web page - Automation Anywhere

I just need to click on "OK" , the pop up generated by web page , i m not able to perform click operation on pop-up generated by web page in Automation Anywhere
enter image description here
Normally the object Cloning command works on that type of windows, you just need to put the main window of the object cloning as "Message from webpage" instead of the main webpage.
If not Image recognition shpuld work perfectly
You can use selenium. use find_by to locate the popup element.
close_button = driver.find_elements_by_class_name("popover-x-button-close")[0]
close_button.click()
sum_div.click()
driver.implicitly_wait(2)

TestCafe Click Spawned Pop Up to Save CSV File

I can't find any way to click "Save" on a pop up that spawns during a test. TestCafe needs to click the "Save" button so I can obtain the CSV file.
I've tried searching for a way to do this in the docs but the closest thing I found so far is .pressKey('enter'). However, this fails to click 'Save' and I don't know what other options I have.
Screenshot of exactly what I'm trying to click:
enter image description here
I provided the end of my code (you'll have to assume all the prior parts of a TestCafe test are preceeding this:
.click(export_button)
.click(csv_pill)
.wait(3000)
.pressKey('enter')
I expect to somehow be able to have the mouse detect this 'Save' button and it clicks it to save this CSV file.
TestCafe cannot test native browser dialogs. They should be prevented. If you encountered this behavior during the test, please create a bug report with a simple example page or link to a tested site.

Can I make popup screen or file upload automatically with selenium?

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");

Automating "Browse" button event in Selenium

I need to automate the "Browse" button click from Selenium.
For this, I have tried
driver.findElement(By.xpath("//*[#id=\"dnn_ctr383_View_filename\"]")).click();
and
driver.findElement(By.cssSelector("Css path")).click();
Both gives me org.openqa.selenium.NoSuchElementException: Unable to locate element: exception.
I have seen this link here where the author suggest to use AutoIT, but in step 2, the script, the author has created is for IE. Can someone please suggest, how I can automate the "Browse" button click in firefox?
Any help is much appreciated.
Directly send the file path to the id, like so
driver.findElement(By.id("dnn_ctr383_View_filename")).sendKeys("C:\\path\\to\\file");
The above step is the answer for your first two steps
Click on Browse
Select a file to upload
For the third step(click upload), looking at the screen capture I do not see any button which says "Upload". So just click "Save" and I assume that your file will successfully get uploaded.
There are two things that u need to consider here:
Clicking the browser button: Usually handled by an alert or popup, if the driver is not able to find the element by xpath(which u have acquired from firebug or chrome's inspect element) you should consider looking for iframes in the page source. If an element is in a different frame altogether , u need to switch frames in order to find the element like this
WebElement frame = driver.findElementById("name_of_iframe");
driver.switchTo().frame(fr);
now you can find your element using xpath or css selector like u did. Once completed u can move out of the frame by:- driver.switchTo().defaultContent();
Uploading the file from desktop: Since selenium works only on the html in the browser session u invoked from the driver, it can't perform operations on your desktop.Once you are able to click the browser button u can use Auto it(works only on windows) or Sikuli(works with mac, linux, windows and even android) to simulate your events based on the position of your upload button.
Hope this helps