Wednesday 12 April 2017

Working With Popup Windows

                                                
                                             Working With Popup Windows

                                There are different type of windows in selenium
                                        
                                     1. Javascript Alert popups.
                                     2. Windows Alert popups.


 1. Javascript Alert Popup :
                                            Selenium provides an Alert class for working with javascript alerts. Method switchTo() to be used to switch driver context to the alert box before any user action can be taken it.

                   Alert alert = driver.switchTo().alert()

    Methods of Alert class :
                 
                   a. accept() :  This method clicks on the 'OK' button of the alert box.
                                       
                                        Syntax:                                                   
                                        driver.switchTo().alert().accept();

                     
                                       


                   b. dismiss() : This method clickes on the 'Cancel' button of the alert box.

                                         Syntax :
                                         driver.switchTo().alert().dismiss();
                                        
                                       
                     c. getText() : This method retrives the text displayed on the alertbox.             
                                         
                                           Syntax :
                                           driver.switchTo().alert().getText();



                    d. sendKeys() : This method will write the specified text string on the alert
                                               prompt box.
                                      
                                             Syntax :
                                             driver.switchTo().alert().sendKeys("Your Text Here");
                                           


2. Windows Alert Popups :
                                            We can handle these popus using two ways.
                                             1. Using third party Auto IT tool.
                                             2. Using Robot Class.


 

No comments:

Post a Comment