Handle Print Dialog

784 views
Skip to first unread message

Gulshan Saini

unread,
Feb 20, 2012, 4:33:45 AM2/20/12
to seleniu...@googlegroups.com
Hello,

I am facing little problem in handling the print dialog. I am using following code and it is not working

JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("window.print = function() {return null}");

Browser FF: 3.6
Selenium: 2.18

Script

 public class Test {

   
    public static void main(String[] args) {
   
        WebDriver driver = new FirefoxDriver();
        Selenium selenium = new WebDriverBackedSelenium(driver, "http://www.quackit.com/javascript/examples/");
        selenium.open("/");
       
        String mainWindow = driver.getWindowHandle();
        driver.findElement(By.xpath("//*[@id='content']/table/tbody/tr[4]/td[3]/a/img")).click();
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("window.print = function() {return null}");
               
       

    }

}

Please advise.

Thanks
Gulshan

Krishnan Mahadevan

unread,
Feb 20, 2012, 6:20:34 AM2/20/12
to seleniu...@googlegroups.com
Gulshan,
Have you been able to work with the print dialog in Selenium 1 ?
AFAIK you wont be able to make use of Selenium to work with O.S dialogs (print dialog is one such dialog). You might have to use AutoIt for handling it.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Gulshan

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/D6VQLzTEx2cJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Gulshan Saini

unread,
Feb 20, 2012, 6:57:40 AM2/20/12
to seleniu...@googlegroups.com
I haven't tried it in Selenium 1.

I downloaded the Autoit but I am unable to locate the recorder.


Any clue?

Thanks
Gulshan

Jayaraman - Inspired to become Software Architect

unread,
Feb 20, 2012, 7:26:16 AM2/20/12
to seleniu...@googlegroups.com
Correct me if I understood wrong?
 
AFAIK, you cant locate those dialog using Firebug. As they are windows objects/components, you have to use those dialog objects to handle that.

-Jay!!


Thanks
Gulshan

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/aG4qmd0cIh0J.

Gulshan Saini

unread,
Feb 20, 2012, 10:59:08 AM2/20/12
to seleniu...@googlegroups.com
I tried Autoit and I created .exe file to handle Print Dialog box. When I manually call the script the print dialog box disappers.
But when I call it via java code it gets stuck at following line of code.

driver.findElement(By.xpath("//*[@id='content']/table/tbody/tr[4]/td[3]/a/img")).click();


Nothings happens after this code. I even did system.out.println("After Click") - Even this line of code is not executed.
 What I think is the webdriver tries to give control to Windows dialog and is not able to do any action after that.
Reply all
Reply to author
Forward
0 new messages