Hello Friends ,
In this Post , I am going to show how to identify different kind of Popups and how to handle them in Selenium.
1- Hidden division Popup
Tips to Identify:
- We can inspect this Popup with right click-Inspect
- This Popup we cannot move
- Also this Popup will be colorfull.
By using the above tips you can easily identify Hidden Division Pop-Up
Handling Technique:
Since We can inspect these kind of Popup , so we can easily find elements in this Pop-up using
driver.findElement(By.xpath("xpath of element"));
2- JavaScript Popup :
Tips to Identify:
- Javascript Popup appears just below (for chrome browser) the address bar at center place
- For Browsers other than chrome , it appears in middle of the page
- Javascript Popup have just OK button for Alert Popup
- For Confirmation Alert it has OK and Cancel button
- We cannot inspect Element in this Popup
Handling Technique:
We can handle this alert Popup using switchTo().alert() method
a- Get the Text of alert Popup -
driver.switchTo().alert().getText();
b-Click OK-
driver.switchTo().alert().accept();
c-Click Cancel in Confirmation Popup -
driver.switchTo().alert().dismiss();
3- Child Browser Popup :
Tips to Identify:
- We can inspect this Popup with right click-Inspect
- We can move this Popup
- Popup will be colourfull
- Will have minimize and maximize button
Handling Technique:
Whenever we open any browser , one window handle id is allocated to that browser.
So All opened browser (parent and child ) are having their respective window handle ids
To get the window handle id of current browser we use method
driver.switchTo().window(window handle );
Example- Switching to each child browsers
//Enter URL in browser
driver.get("https://www.naukri.com/");
//get parent window handle
String parentwindow = driver.getWindowHandle();
//get all opened browsers window handle ids and store in a list
Set<String> allWindows = driver.getWindowHandles();
//Print the count of all opened windows
System.out.println(allWindows.size());
//remove parent window id from All windows handle ids
allWindows.remove(parentwindow);
//using for each loop, iterating to each window
for (String s : allWindows) {
System.out.println(s);
//switching to child windows and perform action
driver.switchTo().window(s);
System.out.println(driver.getTitle());
}
//switch back to parent window
driver.switchTo().window(parentwindow);
4- File Upload Popup :
Tips to Identify:
- When we click on Browse,Upload, Attach icon , this Popup appears
- We can move this Popup but we cannot inspect it
- This Popup is used to Select the document/file from Local machine.
Handling Technique:
In this technique , we do not click on upload button,
To Handle this Popup below are the steps followed:
1-Inspect and find Upload button
2-Use sendKeys() method and give absolute path of the file stored in local PC as and argument to sendKeys() method.
driver.findElement(By.xpath("//input[@value='Upload CV']")).sendKeys("D://sample resume.doc");
5- Notification Popup :
Tips to Identify:
- This Popup appears just below the address bar but at the left side of the page.
- We cannot move this Popup
- This Popup having Allow and Block button
Handling Techniques ( for chrome browser):
We need to change settings of chrome browser, this can be done using ChromeOptions class.
for other browser need to use repective browser Options class to change the settings
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notification");
WebDriver driver = new ChromeDriver(options);
Casinos Near Harrah's Casino & Hotel, Chester, PA
ReplyDeleteA 구미 출장안마 map showing casinos 안양 출장안마 and 영주 출장샵 other gaming facilities 양주 출장안마 located near Harrah's Casino & Hotel in 여주 출장마사지 Chester, Pennsylvania, United States.