SlideShare a Scribd company logo
1 of 4
Download to read offline
SELENIUM Cheat Sheet
Creating Driver:
Action Selenium code Description
Firefox driver WebDriver Driver = new FirefoxDriver (); Driver is an object
IE driver System.setProperty("webdriver.ie. driver”, PATH);
WebDriver driver = new InternetExplorerDriver ();
PATH = path of IEDriver exe file;
chrome Driver System.setProperty("webdriver.ie. driver",PATH);
WebDriver driver = new ChromeDriver ();
PATH = path of chrome exe file;
Identify Elements:
Action Code Description
Find single Element driver.findElement(locator) Locator is a location of
element
Find multiple Elements driver.findElements(locator) Locator is a location of
element
Locating UI Elements:
Action Code Description
By ID driver. findElement (By.id(str)); Str is id of element
By Name driver.findElement(By.name(str)); Str is name of element
By class name driver. findElement (By. className(str)); Str is class value of element
By CSS selector driver.findElement(By.cssSelector(str)); Str is cssSelector of element
By link text driver.findElement(By.linkText(str)); Str is link text of element
By partial link text driver.findElement(By.partialLinkText(str)); Str is partial text of element
By tag name driver.findElement(By.tagName(str)); Str is tag name of element
By XPath driver.findElement(By.xpath(xpath)); Str is xpath of element
Handling Java Script Alerts:
To handle alert first we need to switch to alert.
Alert al=driver.switchTo().alert();
The Actions list.
Action code
Click on ok in alert al.accept();
Click on cancel. al.dismiss()
Type in alert box. al.sendKeys(“text”);
Get text from alert box. al.getText();
Capture Screen Shot of Browser:
Action Code Description
Capture screen File scrFile1 =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FIL
E);
It captures screen shot
of particular page and
stores it in variable
Save to disk FileUtils.copyFile(scrFile1, new File("c:tmpk2.png")); Save screen shot as
k2.png
User Actions:
Action Code Description
Write in text fields driver.findElement(locator).sendKeys(text); Text: what u want to write
locator is a location element
Click button or click radio
button or check box
driver. findElement(locator). click(); locator is a location element
Clear text in text field driver. findElement(locator). clear(); locator is a location element
Navigate back and forward
in browser
driver.navigate(). back();
driver.navigate().forward();
Navigate to frame driver. switchTo().frame(frame); frame can be integer value
represents position of frame or
string represents id of frame or
WebElement represents frame of
frame.
Navigate to next window
or pop up window
driver.switchTo().window(hashCode); hashCode is hash code of window
Get inner text of element
or inner text of table
driver.findElement(locator).getText(); locator is a location element
Working on auto
complete/suggestions
Or Calendar pop up
driver. findElement(locator). click(); Get the locator of hidden division
or element and perform required
operation.
select drop down list:
Using Select class we can work on select drop down. Create select object for specific select
drop down.
//creating webelement for select dropdown
WebElement usrs=driver.findElement(By.name(“users”));
Select usr=new Select(usrs);
We can select options of drop down in 3 different ways as explained below:
Action code description
Select by using id of option tag usr.selectById(ID); ID is string, value of id attribute of
option.
Select by using index of option tag usr.selectByIndex(i); i is the position of option
Select by using visible text in option
tag
usr.selectByVisibleText(str) str is the text inside option tag.
Working on excel sheet:
Before working on excel first we need to read excel in input stream using file io stream.
FileInputStream fis=new FileInputStream(“Path of .xlsx file”);
Action Code Description
Convert file io into
workbook
Workbook wb = WorkbookFactory.create(fis); Create function creates work
book.
Get into specified
sheet
Sheet s = wb.getSheet(sheetName);
Or
Sheet s = wb.getSheetAt(sheetNum);
sheetName is name of the
sheet
sheetNum is index of sheet
Get into specified
row
Row r = s.getRow(rowNum);
Get into specified
column
Cell c = r.getCell(colNum);
Get cell value String cellVal = c.getStringCellValue();
Or
boolean b = c.getBooleanCellValue();
or
Date d = c.getDateCellValue();
Or
int I = c.getNumericCellValue();
Get cell value based on value in
excel cell
Get row count int I = s.getLastRowNum();
Get Column count int j = r. getLastCellNum ();
Write back to excel c.setCellValue("PASS1");
FileOutputStream fos = new
FileOutputStream("Path of .xlsx file ");
wb.write(fos);
fos.close();
Drag, Drop and Mouse Over, Mouse Events:
We use Actions Class for drag and drop
Create an object to action class
Actions a=new Actions(driver);
Action code description
Drag and Drop
using source and
destination
a.dragAndDrop(src, des).build().perform(); Src and dest is the
WebElement object of
source and destination
of drag and drop
element.
Drag and drop to
specific position
a.dragAndDrop(src, x,y).build().perform(); x and y are integer
values for specific
position.
Mouse over on
specific element.
a.moveToElement(element).build().perform(); Element is an object of
WebElement which
points to required
element.
Mouse right click a.contextClick(element).build().perform(); Element is an object of
WebElement which
points to required
element.
Mouse
movement after
right click
a.sendKeys(Keys.<keyboardstrokes>).build().perform(); Keys is a class contains
all key strokes such as
right left, enter, back
button.

More Related Content

What's hot

Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-AssuredMichel Schudel
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaEdureka!
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
Important React Hooks
Important React HooksImportant React Hooks
Important React HooksKnoldus Inc.
 
Selenium interview-questions-freshers
Selenium interview-questions-freshersSelenium interview-questions-freshers
Selenium interview-questions-freshersNaga Mani
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessibleVictor Trakhtenberg
 
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Selenium locators: ID, Name,  xpath, CSS Selector advance methodsSelenium locators: ID, Name,  xpath, CSS Selector advance methods
Selenium locators: ID, Name, xpath, CSS Selector advance methodsPankaj Dubey
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTDr. Awase Khirni Syed
 

What's hot (20)

Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-Assured
 
Selenium WebDriver training
Selenium WebDriver trainingSelenium WebDriver training
Selenium WebDriver training
 
Selenium IDE LOCATORS
Selenium IDE LOCATORSSelenium IDE LOCATORS
Selenium IDE LOCATORS
 
Selenium
SeleniumSelenium
Selenium
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Reactjs
ReactjsReactjs
Reactjs
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Important React Hooks
Important React HooksImportant React Hooks
Important React Hooks
 
Selenium introduction
Selenium introductionSelenium introduction
Selenium introduction
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Selenium interview-questions-freshers
Selenium interview-questions-freshersSelenium interview-questions-freshers
Selenium interview-questions-freshers
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Selenium locators: ID, Name,  xpath, CSS Selector advance methodsSelenium locators: ID, Name,  xpath, CSS Selector advance methods
Selenium locators: ID, Name, xpath, CSS Selector advance methods
 
reactJS
reactJSreactJS
reactJS
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENT
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 

Similar to Selenium cheat sheet

APPlause - DemoCamp Munich
APPlause - DemoCamp MunichAPPlause - DemoCamp Munich
APPlause - DemoCamp MunichPeter Friese
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseHeiko Behrens
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderAndres Almiray
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserializationYoung Alista
 
"Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk "Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk Fwdays
 
𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdf
𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdf𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdf
𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdfsinghsibasis2
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1saydin_soft
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Svetlin Nakov
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptAntoJoseph36
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180Mahmoud Samir Fayed
 

Similar to Selenium cheat sheet (20)

APPlause - DemoCamp Munich
APPlause - DemoCamp MunichAPPlause - DemoCamp Munich
APPlause - DemoCamp Munich
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Protractor Training in Pune by QuickITDotnet
Protractor Training in Pune by QuickITDotnet Protractor Training in Pune by QuickITDotnet
Protractor Training in Pune by QuickITDotnet
 
Protractor Training - Online training On Skype
Protractor Training - Online training On Skype Protractor Training - Online training On Skype
Protractor Training - Online training On Skype
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
srgoc
srgocsrgoc
srgoc
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
"Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk "Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk
 
Cis166 final review c#
Cis166 final review c#Cis166 final review c#
Cis166 final review c#
 
𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdf
𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdf𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdf
𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝘂𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮.pdf
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180
 
Php sql-android
Php sql-androidPhp sql-android
Php sql-android
 

Recently uploaded

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 

Recently uploaded (20)

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 

Selenium cheat sheet

  • 1. SELENIUM Cheat Sheet Creating Driver: Action Selenium code Description Firefox driver WebDriver Driver = new FirefoxDriver (); Driver is an object IE driver System.setProperty("webdriver.ie. driver”, PATH); WebDriver driver = new InternetExplorerDriver (); PATH = path of IEDriver exe file; chrome Driver System.setProperty("webdriver.ie. driver",PATH); WebDriver driver = new ChromeDriver (); PATH = path of chrome exe file; Identify Elements: Action Code Description Find single Element driver.findElement(locator) Locator is a location of element Find multiple Elements driver.findElements(locator) Locator is a location of element Locating UI Elements: Action Code Description By ID driver. findElement (By.id(str)); Str is id of element By Name driver.findElement(By.name(str)); Str is name of element By class name driver. findElement (By. className(str)); Str is class value of element By CSS selector driver.findElement(By.cssSelector(str)); Str is cssSelector of element By link text driver.findElement(By.linkText(str)); Str is link text of element By partial link text driver.findElement(By.partialLinkText(str)); Str is partial text of element By tag name driver.findElement(By.tagName(str)); Str is tag name of element By XPath driver.findElement(By.xpath(xpath)); Str is xpath of element Handling Java Script Alerts: To handle alert first we need to switch to alert. Alert al=driver.switchTo().alert(); The Actions list. Action code Click on ok in alert al.accept(); Click on cancel. al.dismiss() Type in alert box. al.sendKeys(“text”); Get text from alert box. al.getText();
  • 2. Capture Screen Shot of Browser: Action Code Description Capture screen File scrFile1 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FIL E); It captures screen shot of particular page and stores it in variable Save to disk FileUtils.copyFile(scrFile1, new File("c:tmpk2.png")); Save screen shot as k2.png User Actions: Action Code Description Write in text fields driver.findElement(locator).sendKeys(text); Text: what u want to write locator is a location element Click button or click radio button or check box driver. findElement(locator). click(); locator is a location element Clear text in text field driver. findElement(locator). clear(); locator is a location element Navigate back and forward in browser driver.navigate(). back(); driver.navigate().forward(); Navigate to frame driver. switchTo().frame(frame); frame can be integer value represents position of frame or string represents id of frame or WebElement represents frame of frame. Navigate to next window or pop up window driver.switchTo().window(hashCode); hashCode is hash code of window Get inner text of element or inner text of table driver.findElement(locator).getText(); locator is a location element Working on auto complete/suggestions Or Calendar pop up driver. findElement(locator). click(); Get the locator of hidden division or element and perform required operation. select drop down list: Using Select class we can work on select drop down. Create select object for specific select drop down. //creating webelement for select dropdown WebElement usrs=driver.findElement(By.name(“users”)); Select usr=new Select(usrs); We can select options of drop down in 3 different ways as explained below:
  • 3. Action code description Select by using id of option tag usr.selectById(ID); ID is string, value of id attribute of option. Select by using index of option tag usr.selectByIndex(i); i is the position of option Select by using visible text in option tag usr.selectByVisibleText(str) str is the text inside option tag. Working on excel sheet: Before working on excel first we need to read excel in input stream using file io stream. FileInputStream fis=new FileInputStream(“Path of .xlsx file”); Action Code Description Convert file io into workbook Workbook wb = WorkbookFactory.create(fis); Create function creates work book. Get into specified sheet Sheet s = wb.getSheet(sheetName); Or Sheet s = wb.getSheetAt(sheetNum); sheetName is name of the sheet sheetNum is index of sheet Get into specified row Row r = s.getRow(rowNum); Get into specified column Cell c = r.getCell(colNum); Get cell value String cellVal = c.getStringCellValue(); Or boolean b = c.getBooleanCellValue(); or Date d = c.getDateCellValue(); Or int I = c.getNumericCellValue(); Get cell value based on value in excel cell Get row count int I = s.getLastRowNum(); Get Column count int j = r. getLastCellNum (); Write back to excel c.setCellValue("PASS1"); FileOutputStream fos = new FileOutputStream("Path of .xlsx file "); wb.write(fos); fos.close();
  • 4. Drag, Drop and Mouse Over, Mouse Events: We use Actions Class for drag and drop Create an object to action class Actions a=new Actions(driver); Action code description Drag and Drop using source and destination a.dragAndDrop(src, des).build().perform(); Src and dest is the WebElement object of source and destination of drag and drop element. Drag and drop to specific position a.dragAndDrop(src, x,y).build().perform(); x and y are integer values for specific position. Mouse over on specific element. a.moveToElement(element).build().perform(); Element is an object of WebElement which points to required element. Mouse right click a.contextClick(element).build().perform(); Element is an object of WebElement which points to required element. Mouse movement after right click a.sendKeys(Keys.<keyboardstrokes>).build().perform(); Keys is a class contains all key strokes such as right left, enter, back button.