Unable to pen MS Word Document from Firefox browser - selenium

In Selenium, When I try to open MS Word Document from Firefox browser, dialog box pop-ups which I am unable to identify through Selenium. Can any one please help me in identifying the dialog box (How to capture ID or window ID) through selenium?

You can use autoit.Just Download the autoit software from given link and install it.
AutoIt Site
Write a few lines script in autoit according to your need and call the compiled exe before the line which causes that window to appear.
The Autoit WIndow Info Tool will help you in identifying the ID and class for the desired controls.

Related

Unable to access the print button through selenium webdriver as it is within shadow-root

enter image description hereThere is a scenario that I am trying to automate through selenium webdriver (Java) and facing trouble. Print preview is not accessible through selenium as it is within shadow-root. Our task is to download the pdf files from web portals. When we clicked on print button on web, print preview window is opened and we need to click on save button in this print preview window in order to download the pdf. And also linked the URLs of the solutions that I have tried to solve this problem. for screenshot enter image description here
https://www.seleniumeasy.com/selenium-tutorials/accessing-shadow-dom-elements-with-webdriver
How to interact with the elements within #shadow-root (open) while Clearing Browsing Data of Chrome Browser using cssSelector
Handle Print Preview window using selenium in chrome latest version
How can I tell Selenium to press cancel on a print popup?
Selenium how to click Ctrl + p
How to click on the print button on a web page using Selenium
Try with mouse / keyboard actions libraries :
Library pyautogui
Library ImageHorizonLibrary
Check keywords :
pyautogui.Key Down 'enter'
ImageHorizonLibrary.Press Combination Key.enter
The above libraries have additional keywords that should help.

How to handle window open prompt(native) in webdriver.io

I am using webdriver.io framework. At my application, I have a button that opens a Windows Open prompt (Native), and there I need to choose a folder/file and click Open.
Then returning to my application and continue.
Is there a way to move focus on to this window and control it (Select a path and click Open)?
If not- Is there any other solution someone can offer?
The short answer is probably not, you can't control native dialogs from webdriver.
If it's a file input type for which you want to set a file, you might possibly use webdriver to evaluate a piece of javascript to set the HTMLInputElement.files value of the input element.
This works in modern browsers as mentioned in the mozilla docs

Using selenium drivers to Print to PDF

I am struggling with a problem.
I need to download PDF file when the Print dialog appears.
Here is an example of the dialog
I have tried both the chrome and firefox drivers. But unfortunately still cannot get it working.
I have found the following preference for the firefox
fp.setPreference("print.print_to_file", true);
But it seems that it doesn't work.
It doesn't even get applied into the configuration variables set.
Please suggest any way to automate some actions with selenium and then save to PDF file when this print dialog appears.
Firstly, you need to know selenium is a web automation tool. so it can only operate things belongs to browser. Even that, it can't operate all things belongs to browser, like address bar, favior bar, menu bar of browser.
For most case, the print dialog is not belongs to browser, it supplyed by OS or other software installed on OS. so selenium can't operate it is reasonable.
If your script code by java, you can use java.awt.robot to capture the dialog
and click 'print to file'.
If java.awt.robot can worked as your expect, I think you aslo need to set browser options in your script to give a path for browser to save the printed file, just like when you download file, browse will ask you where to save.
if you not to set that options, i guess it will pop-up another dialog to ask you where to save and this dialog is also not belongs to browser.
it's not easy to use java.awt.robot to set the save path.
Because you need to consider the possbility of script run on different OS, use abosulte path is not workable on different OS. Besides if your script run with seleniu grid, it will make you craze. So if testing print to file feature is not important, i recommend you test it manuall.
You can automate Print to PDF using Testmate as below
http://thetestmate.com/save-as-pdf-in-chrome-testmate-selenium/

Selenium select folder windows dialog

]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.

Identifying word documents opened by Selenium Webdriver

In my Selenium project word document is being opened as a report.
How can I identify whether the document is opened or not using Selenium webdriver.
In short, unless the document opens utilizing the browser, then you can't with Selenium WebDriver. Selenium only has access to what the browser itself has access to. If the browser is handing this off to the OS or MS Office to handle the specifics then you lose access to it.
You could try to intercept the communication and determine when the code to call the word document to open is executed, but that would be custom code and depend on the application itself.
Personally I think the best way would be to instantiate an OpenQA.Selenium.Interactions.Actions class instance and then specify the specific keystrokes to capture the screen and save it. Then switch back to the browser window driver.switchto().window() and continue. Then you can verify manually that the screen capture has the word document in it after the test is completed.