2. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
About Me :
Total Experience:- 3.3 years
Previous Companies: Qualitree Solutions Pvt. Ltd.
PointCross.com Pvt. Ltd.
Certification:- Vskills(VS-1083) Selenium Certification
Skills :- Selenium RC, Selenium WebDriver, QTP, Manual
Testing,SQL
3. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
AGENDA / Topic INDEX
--> Wait Commands
1. Implicit Wait
2. Explicit Wait
--> How to handle alerts
--> How to switch to window
--> How to retrieve Text of all the links
--> How to do Mouse Over action
--> How to do Drag & Drop action
--> How to scroll to Element
--> How to take snapshot
--> How to read pdf contents
4. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
--> Wait Commands
1. Implicit Wait
2. Explicit Wait
Implicit Wait
------------------
Implicit Wait will wait for whole DOM (Document Object
Model) to be loaded for the specified time. If not then it
wil thoroe timeout exception.
e.g.
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SE
CONDS)
Explicit Wait
------------------
Explicit Wait will wait for certain condition to occur.
5. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to handle Alerts
----------------------------
// Wait For Alert To Come
WebDriverWait wait = new
WebDriverWait(driver,30);
Alert alert =
wait.until(ExpectedConditions.alertIsPresent());
// Get the Text From the Alert
String alertText = alert.getText();
System.out.println("Alert Text :"+alertText);
alert.accept();
Or
alert.dismiss();
6. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to switch to Window
---------------------------------
// Store the CurrentWindow for future reference
String currentWindow = driver.getWindowHandle();
String popupWindowHandle = null;
// Switch To Popup Window
for(String handle : driver.getWindowHandles()){
if(!handle.equals(currentWindow)){
popupWindowHandle = handle;
}
}
driver.switchTo().window(popupWindowHandle);
7. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to scroll to element
-----------------------------------------
// Assign Object for Last Train
WebElement lastTrain =
driver.findElement(By.xpath("//*[@id='divTrainsListTrainsObj']/table[1]/tbody/tr[27]/td[2
]/a"));
// Scroll to Last Train
Coordinates coordinate = ((Locatable) lastTrain).getCoordinates();
coordinate.inViewPort();
How to take snapshot
------------------------------
// Take ScreenShot
File scrFile = ((TakesScreenshot)
driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:seleniumscreenshot.png"),
true);
8. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to retrieve Text of all the links
-----------------------------------------
// Verify Links
List<WebElement> listOfLinks = driver.findElements(By.tagName("a"));
String linkText[] = new String[listOfLinks.size()];
int i=0;
for(WebElement l1: listOfLinks){
// Get Link Text
linkText[i] = l1.getText();
System.out.println(linkText[i]);
i++;
}
// Click on Links
for(String t : linkText){
driver.findElement(By.linkText(t)).click();
if(driver.getTitle().contains("Under Construction")){
System.out.println(t+" : Link is under construction");
}
driver.navigate().back();
}
9. Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
How to read PDF contents
-----------------------------------------
// Required JAR files
1. fontbox-1.8.5.jar
2. pdfbox-1.8.5.jar
// Read PDF Contents
PDDocument pd;
pd = PDDocument.load(new File("D:seleniumVS-1083_Certified
Selenium Professional_Reading_Material.pdf"));
System.out.println("Total Number Of pages :"+pd.getNumberOfPages());
PDFTextStripper pdf = new PDFTextStripper();
System.out.println(pdf.getText(pd));