Alert

There are 8 types of alerts
      1. javascriptpopups
      2.webpushnotifications
      3.chatboot
      4.Authntication popups
      5.windows basedalerts
      6.html light box
      7. window popups
   



javascript popups:


1.simple popups  :::: https://ksrtc.in/oprs-web/ ----- enter search button with out entering locations then you will find simle javascript alert


  driver.get(" https://ksrtc.in/oprs-web/");
driver.findElement(By.xpath("//button[@class='btn btn-primary btn-lg btn-block btn-booking']")).click();
Thread.sleep(10000);
Alert alert=driver.switchTo().alert();
System.out.println(alert.getText());
alert.accept();
       
2.sendsometextpopups


alert.sendkeys("gyusvusf");

3.warning popus
                                           alert.accept();
                                           alert.disimiss();
                                          alert.gettext();




WebPushnotification:



       to see the configuration present in chrome is about:config chrome=chromeoptions option=new chromeoptions();
option.addarguments(disable--notifications)
then we have to pass reference variable to opening driver as a constuctor
driver=new chromedriver(option)

firefox=
         to see the configuration present in firefox is chrome://flags

    firefoxoptions opt=new firefoxoptions
options.addprefrence("dom.webnotifications.enabled",false)
driver=new firefoxdriver(opt);



chatbot:


    this chatbox directly intracts with driver instance we can directly close by locator


Authentication popups:
       url="http://the-internet.herokuapp.com/basic_auth"

   in this popupups if you want to pass anything first you have to pass username and password


http://admin:admin@the-internet.herokuapp.com/basic_auth by this way we can remove this authentication popups by using selenium




windows based alerts:
               we cannot directly intreact with windows based popups  so we have use other third party apps like sikuli and robot framework and autoit

   sikuli:
           screen sc=new screen();
       Syntax:
Screen s=new Screen();
#2: Click On An Element
This method used to Click on the specific image present on the screen.
Syntax:
s.click(“<<image name>>”);
Example:
s.click(“test.png”);
#3: Right Click On An Element
This method used to right click on the specific image present on the screen.
Syntax:
s.rightClick(“<<image name>>”);
Example:
s.rightClick(“test.png”);
#4:  find An Element
This method used to find a specific element present on the screen.
Syntax:
s.find(“<<image name>>”);
Example:
s.find(“test.png”);
 #5: Double Click on An Element
This method used to trigger a double click event on a specific image present on the screen.
Syntax:
s.doubleClick(“<<image name>>”);
Example:
s.doubleClick(“test.png”);
#6: Check whether an Element present on the Screen
This Method is used to check whether the specified element is present on the screen.
Syntax:
s.exists(“<<image name>>”);
Example:
s.exists(“test.png”);
#7: Type a string on a Textbox
This Method is used to enter the specified text on the Text box.
Syntax:
s.type(“<<image name>>”,”String to be typed”);
Example:
s.type(“test.png”,”HI!!”);
#8: Wheeling on a particular image
This method is used to perform wheeling action on the element image.
Syntax:
s.wheel(“<<image name>>”,<<int position>>,<<int direction>>);
Example: 
s.wheel(“test.png”,25,0);
 #9: Drag and Drop a Image/ElementThis method is used to drag and drop a specified image from source position to target position.
Syntax:   
s.dragDrop(“<<source image name>>”,”<<target image name>>”);
Example:       
s.dragDrop(“test.png”,”test1.png”);
#10: Roll Hover on a particular image
This method is used to perform roll hover event on the specified image.
Syntax:
s.hover(“<<image name>>”);
Example:
s.hover(“test.png”);

Html Lightbox:
it is a simple popups when we press on the otherthan popups it will automatically close


Windows popups: this is thesolution and this is also reusable method because i never passed a hard coded value.

 driver.get("https://www.naukri.com/");
String parent=driver.getWindowHandle();
Set<String>set=driver.getWindowHandles();
Iterator it=set.iterator();
while(it.hasNext()) {
String child=(String) it.next();
if(!parent.equalsIgnoreCase(child)) {
driver.switchTo().window(child);
System.out.println(driver.switchTo().window(child).getTitle());
driver.close();
}

}
Thread.sleep(10000);
driver.switchTo().window(parent);
System.out.println(driver.switchTo().window(parent).getTitle());

Thread.sleep(10000);



Comments

Popular posts from this blog

Selenium Locators usage

Java Theory interview questions

java programmes frequently asked in interview