How to handle "Print" and “Save Print output as” browser window popup and How to download the file?

1,214 views
Skip to first unread message

vinus...@gmail.com

unread,
Oct 29, 2018, 8:43:57 AM10/29/18
to Selenium Users
1. I have to visit an URL, login using credentials, then select a region name and click on show button so that a recent bill in the HTML page is shown (all this I did using a Selenium script).
2. There is a button Print Option on that web page. When clicked the print popup appears and I need to click OK. But I am not able to do so using an AutoIt script either.
3.When a click on OK is done, then "Save Print Output As" window opens where I have to enter the file name and click Save.
4.These two pop-up windows differ for Firefox and Chrome. How to handle these? I tried using an AutoIt script and by calling it using Runtime .exec(file name) in a Selenium script, but neither works for me.

5. I used following code -
WinWait("Print", "", 5000)

If WinExists("Print", "") Then
    Send("OK{ENTER}")
EndIf

Sleep(5000)
WinWait("Save Print Output As", "", 5000)

If WinExists("Save Print Output As", "") Then
    ControlFocus("Save Print Output As", "", "Edit1")
    Sleep(5000)
    ControlSetText("Save Print Output As", "", "Edit1", "H282")
    Sleep(5000)
    ControlClick("Save Print Output As", "", "Button2")
EndIf

Please find the attachments and please do the needfull and help me out ASAP 
printppop.JPG
saveprintoutputas.JPG

vinus...@gmail.com

unread,
Nov 12, 2018, 1:11:28 AM11/12/18
to Selenium Users
Please Help me to solve this issue.

Thanks in advance

Imran Khan

unread,
Nov 12, 2018, 1:20:26 AM11/12/18
to seleniu...@googlegroups.com
Hi Vinusha,

Please use "Robot" class to solve this problem. "AutoIT" also would help. But, i am not sure what is the problem there.

So, use "Robot" class. There are many built-in functions and compund literals like VK_ENTER etc. are available.

Thanks,
Imran.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3e40081b-a0e3-44d9-976e-65d8fb35dccd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vinus...@gmail.com

unread,
Nov 12, 2018, 4:41:35 AM11/12/18
to Selenium Users
Hi Imran,

I used the following code but i unable to handle Print POP-UP

String parentHandle = driver.getWindowHandle(); // get the current window handle
driver.findElement(By.xpath("//*[@id='btnPrint']")).click(); // click button that opens a print window

for (String winHandle : driver.getWindowHandles()) {
    driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}
Thread.sleep(4000)
Robot r=new Robot();
r.keyPress(KeyEvent.VK_ENTER);

and also used the Action Class

Actions action = new Actions(driver); 
action.sendKeys(Keys.ENTER).build().perform();

Both these code are not working sir.Can please suggest me with other code or anyother solution.

Imran Khan

unread,
Nov 12, 2018, 5:38:48 AM11/12/18
to seleniu...@googlegroups.com
Hi Vinusha,

I have handled this kind of "Win pop-up" in one of my projects using "Robot" class. Please give me a moment. I will share that particular code chunk with you.

Thanks,
Imran.

Vinusha Govind

unread,
Nov 12, 2018, 6:23:01 AM11/12/18
to seleniu...@googlegroups.com

Vinusha Govind

unread,
Nov 12, 2018, 11:58:22 PM11/12/18
to seleniu...@googlegroups.com
Sir, Please share the particular code ASAP.

with regards
Vinusha

vinus...@gmail.com

unread,
Nov 13, 2018, 7:21:44 AM11/13/18
to Selenium Users
Sir, I am waiting for your reply.
Can please share your code and it will be really helpfull.

Thank you
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

Imran Khan

unread,
Nov 13, 2018, 11:42:56 AM11/13/18
to seleniu...@googlegroups.com
Hi Vinusha,

I have used the below code to upload a document into web portal.

Robot r = new Robot();
driver.findElement(By.id("<selector>")).click();
r.setAutoDelay(2000);

StringSelection s = new StringSelection("<path of the file>");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(s,null);
r.setAutoDelay(5000);

r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);

r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_V);
r.setAutoDelay(1000);

r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);

I am not sure about your requirement. So, please do the changes wherever you want.

Thanks,
Imran.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Imran Khan

unread,
Nov 13, 2018, 11:45:44 AM11/13/18
to seleniu...@googlegroups.com
I am sure it will help you to resolve your issue. 

Please note you no need to set the windows focus to "Win pop-up". It'll automatically take the focus.

alex

unread,
Nov 14, 2018, 2:07:01 AM11/14/18
to seleniu...@googlegroups.com

Hi.

I am using vb.net

Where can I find the robot class ?

Alex

Reply all
Reply to author
Forward
0 new messages