SlideShare a Scribd company logo
1 of 13
Selenium WebDriver Best
Practices
Presenter: Rajendra Narayan Mahapatra, Mindfire
Solutions
Date: 25/06/2014
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
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
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.
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();
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);
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);
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();
}
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));
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
Question and
Answer
Presenter: Rajendra Narayan Mahapatra,
Mindfire Solutions
Thank you
www.mindfiresolutions.com
https://www.facebook.com/MindfireSolutions
http://www.linkedin.com/company/mindfire-solutions
http://twitter.com/mindfires

More Related Content

Viewers also liked

SoftQL - Telecom Triage Services
SoftQL - Telecom Triage Services SoftQL - Telecom Triage Services
SoftQL - Telecom Triage Services Amar Uppalapati
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialAlan Richardson
 
Selenium WebDriver with C#
Selenium WebDriver with C#Selenium WebDriver with C#
Selenium WebDriver with C#srivinayak
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsNick Belhomme
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, SuccessfullySauce Labs
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 
Digital Testing Strategy: Replace Manual Testing with Intelligent Automation
Digital Testing Strategy: Replace Manual Testing with Intelligent AutomationDigital Testing Strategy: Replace Manual Testing with Intelligent Automation
Digital Testing Strategy: Replace Manual Testing with Intelligent AutomationWorksoft
 
Smarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationSmarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationRIA RUI Society
 
Building a Test Automation Strategy for Success
Building a Test Automation Strategy for SuccessBuilding a Test Automation Strategy for Success
Building a Test Automation Strategy for SuccessLee Barnes
 
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy Impetus Technologies
 
Test Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.comTest Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.comIdexcel Technologies
 
Selenium Tips & Tricks
Selenium Tips & TricksSelenium Tips & Tricks
Selenium Tips & TricksDave Haeffner
 

Viewers also liked (15)

SoftQL - Telecom Triage Services
SoftQL - Telecom Triage Services SoftQL - Telecom Triage Services
SoftQL - Telecom Triage Services
 
Selenium Primer
Selenium PrimerSelenium Primer
Selenium Primer
 
Selenium
SeleniumSelenium
Selenium
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver Tutorial
 
Selenium WebDriver with C#
Selenium WebDriver with C#Selenium WebDriver with C#
Selenium WebDriver with C#
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Digital Testing Strategy: Replace Manual Testing with Intelligent Automation
Digital Testing Strategy: Replace Manual Testing with Intelligent AutomationDigital Testing Strategy: Replace Manual Testing with Intelligent Automation
Digital Testing Strategy: Replace Manual Testing with Intelligent Automation
 
Smarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationSmarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automation
 
Building a Test Automation Strategy for Success
Building a Test Automation Strategy for SuccessBuilding a Test Automation Strategy for Success
Building a Test Automation Strategy for Success
 
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Test Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.comTest Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.com
 
Selenium Tips & Tricks
Selenium Tips & TricksSelenium Tips & Tricks
Selenium Tips & Tricks
 

More from Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Recently uploaded

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Selenium Web Driver Best Practices

  • 1. Selenium WebDriver Best Practices Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Date: 25/06/2014
  • 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));
  • 10. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Question and Answer
  • 11.
  • 12. Presenter: Rajendra Narayan Mahapatra, Mindfire Solutions Thank you