Open file dialog using in Java selenium test case - java

In my angular application, I am writing test cases using selenium.
In one of the test suite, I have a scenario where on click of a button, I need to open a Windows FileInput dialog and select a file that is passed and read the data in the file.
How can I achieve this.
I am using like this but nothing happens. How can I achieve this?
driver = Chrome webdriver;
element = driver.find_element_by_id("fileUpload")
element.send_keys("myfile.txt")

Uploading file with Selenium is done not the same way human user does.
With Selenium you should bot click on dialog, open OS browsing dialog, select file and click "upload" button.
With Selenium uploaded file should be sent to a special element presented on the page.
This is not a visible element.
It can be located by following XPath: "//input[#type='file']". The same with CSS Selector "input[type='file']".
Full absolute path to uploaded file should be sent to that element.
Like the following:
driver.findElement(By.xpath("//input[#type='file']")).sendKeys("C:/path/to/file.extension");

Related

How to handle FileUpload using selenium-Webdriver

//div[#id='upload_button']
driver.findElement(By.xpath("//div[#id='upload_button']")).click();
driver.findElement(By.xpath("//div[#id='upload_button']")).sendKeys("V://Images//CSV/text.csv");
I have a upload button in my browser
written a script that will click the button and send the mentioned file from given path
Here it is selecting the Upload button and file explorer opening
Not opening path, to send the csv file
If //input[#type='file'] is present at least one time in the HTML-DOM, the you can directly send the keys, you do not need to
Click on upload button
Select file using explorer
and upload the file.
This feature was introduced in one of the Selenium 3 versions.
Effective code:
driver.findElement(By.xpath("//input[#type='file']")).sendKeys("V://Images//CSV/text.csv");
I would recommend that use explicit wait for more stability.
driver.findElemnt(By.xpath("//input[#type='file'])).sendKeys(" give source file path");

Unable to select a 3 point button in Sharepoint using Selenium WebDriver in Java

I am trying to automate a SharePoint site, using Selenium Java. I want my web driver to go to one file, move it and save it into the target folder.
There is a 3 dot menu, if we click, then it displays options like move, delete, download etc I tried the Xpath but it is not recognizing as there are multiple 3 point buttons for different files in the same webpage with no unique id.
To recognize the button, I used complete XPath but did not work.
Also, can I use the Actions class once I am able to select the button?
Any recommendations?
Copied below is the source code for the button I want to select.
Xpath for button1 (Target folder)
/html/body/div[1]/div[2]/div[1]/div/div[3]/section/article/div/div/div/div/div[1]/div/div/div/div/div/div/div/div/div/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div/div/div[1]/div/div[2]/button[2]
Xpath for button2 (source file)
/html/body/div[1]/div[2]/div[1]/div/div[3]/section/article/div/div/div/div/div[1]/div/div/div/div/div/div/div/div/div/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div/div/div[2]/div/div[2]/button[2]

Users on Chrome OS cannot view .csv or .xls file opened in new tab

We have a simple link that serves up a downloadable version of a report in .pdf, .csv, and .xls formats. Recently, the .csv and .xls options have stopped working for our chromebook users while the .pdf version continues to work as intended. Where the link used to prompt the user for a download, or open in a new tab, it now does nothing. The only workaround other than using a different OS is the following:
Before you go to click "View" to download the link:
Right click on the page and select "Inspect" or press Ctrl Shift i to open the developer tools
On the new screen select the "Console" tab at the top
Click the "View" link to see the report like before
You should notice a warning message in the console at this point
Right click on the link in that warning message
Select open in new tab
The document should open in Google Sheets
The link in the warning message described in the list is a warning thrown by Chrome browser.
Resource interpreted as Document but transferred with MIME type text/csv:
We've released this workaround to our support users, but obviously can't ask clients to use the developer tools to download their file. Any assistance would be greatly appreciated. It should be noted that this problem is only for our Chrome OS users, and not any other users on the Chrome browser.
If you're having trouble inspecting on the current version (Chrome OS) hi-light this javascript code and drag it to your Chrome bookmarks bar:
javascript:alert("Inspect Element On");javascript:document.body.contentEditable = 'true'; document.designMode='on'; void 0;javascript:alert(document.documentElement.innerHTML);

Selenium: How to save a file downloaded, in a specific folder?

I am automating a scenario using Selenium webdriver. When I click on the button using the selenium java script in IE, it downloads an excel file. However I need to click on the "Save As" option in that bar, and then provide a name to it, in the Save As pop-up, and save it in a specific directory.
I doubt if Selenium alone could do this.
Could anyone pls guide me in achieving this

Open an exe window

I want to customize the browser by adding a new button in the main menu the requirement is when i click on the button it should open an exe its working good by opening it in a new window i want the window to be displayed in the browser itself. eg. in mozilla firefox i give a button to open openoffice.exe. Its opening as a new window and i am able to close the browser by keeping the exe file opened. I want to open the exe file of open office in the browser so that when i click the link in the window it opens the new open office writer in the browser itself. Any idea how can i implement that
An exe file (Executable) file is an independent file. It will always run in its own window no matter from where it is called. If you want to open a document in your browser window, simple link the file created in that exe file. For example if you want to show a MS-Word document in the web browser, then instead of providing the link to MS-Word, provide a link to the Word documument (.doc or docx). Remember this behaviour requires that the linked files must have a registered application installed on the computer.

Categories