0% found this document useful (0 votes)
41 views

Selenium Java Notes

The document provides code snippets and descriptions for common Selenium tasks like initializing browser drivers, locating elements, handling frames, alerts and windows, and using explicit waits. It includes the syntax for initializing Chrome, Edge, Firefox and Safari drivers and locating elements by id, name, class, tag name, link text, partial link text, css selector and xpath. It also describes methods for switching frames and windows, accepting/dismissing alerts, and expected conditions for explicit waits.

Uploaded by

Carlos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Selenium Java Notes

The document provides code snippets and descriptions for common Selenium tasks like initializing browser drivers, locating elements, handling frames, alerts and windows, and using explicit waits. It includes the syntax for initializing Chrome, Edge, Firefox and Safari drivers and locating elements by id, name, class, tag name, link text, partial link text, css selector and xpath. It also describes methods for switching frames and windows, accepting/dismissing alerts, and expected conditions for explicit waits.

Uploaded by

Carlos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Initialize

Browser Drivers
Browser Syntax
Chrome WebDriver driver = new ChromeDriver();

Edge WebDriver driver = new EdgeDriver();

Firefox WebDriver driver = new FirefoxDriver();

Safari WebDriver driver = new SafariDriver();


Selenium
Locators
Locator Syntax
className driver.findElement(By.className (“value”))

cssSelector driver.findElement(By.cssSelector(“value"))
id driver.findElement(By.id(“value"))
linkText driver.findElement(By.linkText(“value"))
name driver.findElement(By.name(“value"))
partialLinkText driver.findElement(By.partialLinkText(“value"))
tagName driver.findElement(By.tagName (“value”))

xpath driver.findElement(By.xpath(“value"))
Switch Method
Types For Frames
Method Description
frame(WebElement element) Selects a frame by WebElement

frame(String nameOrId) Selects a frame by its name or ID

frame(int index) Selects a frame by its (zero-based) index

defaultContent() Selects either first frame or main document

parentFrame() Change focus to the parent context


Frame
Example
Alerts/Pop-Ups

Method Description
accept() Accepts the alert

dismiss() Dismisses / cancels the alert

getText() Gets text from the alert

sendKeys() Types text into the alert


Alert
Example
Log Into
Application
Menu
Company Username

Logo Password

Submit
Button

Pop-Up / Alert
Box

OK CANCEL
Switch Method
Types For Windows
Method Description
getWindowHandle() Gets the window handle of the current window

getWindowHandles() Gets the window handle of all current windows

switchTo().window() Switch focus between windows


Switch Windows
Example
Explicit Wait
Example
Selenium
Waits
Selenium Wait Description
Thread.sleep() (Not a Selenium Wait Method) Causes execution to
sleep for a certain number of milliseconds
Page Load Timeout Sets the wait time for a page to load before throwing
an error
Script Timeout Sets the wait time for JavaScript to execute before
throwing an error
Implicit Wait Determines the wait time to search for an element
before throwing an exception
Explicit Wait Pauses execution until time has expired or an
expected condition is met via WebDriverWait class
Fluent Wait A specialization of Explicit Wait that’s extended by
the WebDriverWait class
Explicit Wait
Expected Conditions
1. alertIsPresent() 9. textToBePresentInElementLocated()

2. elementSelectionStateToBe() 10. textToBePresentInElementValue()

3. elementToBeClickable() 11. titleIs()

4. invisibilityOfTheElementLocated() 12. titleContains()

5. invisibilityOfElementWithText() 13. visibilityOf()

6. presenceOfAllElementsLocatedBy() 14. visibilityOfAllElements()

7. presenceOfElementLocated() 15. visibilityOfAllElementsLocatedBy()

8. textToBePresentInElement() 16. visibilityOfElementLocated()


Select From
Drop Down Code Snippet

You might also like