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
Related
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");
//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");
I'm currently implementing an Angular/java webpage to work with different forms for the users.
right now if the users want to edit the pdf, the only way is to download the PDF and go to the downloads folder and open it in Adobe acrobat. Which is not an optimal solution.
Is there any way I can create a button in HTML/Angular webpage that can automate this process to open the PDF in Adobe acrobat? instead of downloading and going to download folder and open it from there?
I tried to use ngx-extended-pdf-viewer to edit the pdf in the browser. But the user needs to highlight, stamp, and email features that are in Acrobat. Does anyone have a solution for this?
thanks
You can display the pdf file in new tab by the line:
window.open(fileUrl, '_blank');
The fileUrl is a variable that contains the file path. You can fetch it after the download is complete.
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]
I need to click on a pdf file in the browser and the verify the contents in that,
By using below code am able to click on the pdf link but i can't verify the contents inside that pdf link ,the pdf is embedded in object.
How can we locate an element inside object tag and perform some actions on pdf file(html type).
To click on pdf link..
WebElement element = driver.findElement(By.xpath("//div[#id='iconDock']/div/a[7]/img"));
element.click();
This code to verify content in pdf(its not working).
WebElement objectTag = driver.findElement(By.xpath("//div[string(#id)='reportPanel']//object/html/body//div[#id=\"outerContainer\"]/div[#id=\"viewer\"]/div[#class=\"textLayer\"])"));
Help me out please
you cannot verfiy the contents of the pdf using webdriver, u need to integrate with a tool called PDFBOX.Please find the link to give u basic understanding how to use it.
http://seleniumeasy.com/selenium-tutorials/how-to-extract-pdf-text-and-verify-using-selenium-webdriver-java
Selenium cannot interact with a PDF, it is a library for driving a web browser.
The best advice is don't use WebDriver for downloading files. Use it to get file locations and then use a different library to actually download files.
The easiest way to check a file is take an MD5/SHA1 hash of a known good copy of a file and then compare it with the MD5/SHA1 hash of the file you have downloaded. It's how everybody checks that the file they have downloaded is correct.
More info in this blog post:
http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/