Selenium WebDriver

Browser Operations & Selenium Locators

Master browser operations, navigation methods, and understand all Selenium locators with their differences and best practices.

Browser Operations

Essential Browser Methods

Operation

Open Chrome Browser
Open URL
Capture Browser Title
Capture Browser URL
Navigate to URL
Navigate Back
Navigate Forward
Refresh Browser
Close Focused Window
Close All & Terminate

Method

new ChromeDriver()
driver.get("URL")
driver.getTitle()
driver.getCurrentUrl()
driver.navigate().to("URL")
driver.navigate().back()
driver.navigate().forward()
driver.navigate().refresh()
driver.close()
driver.quit()

Return Type

ChromeDriver
void
String
String
void
void
void
void
void
void

Window Management Operations

Window Operations

• Maximize Browser
• Minimize Browser
• Full Screen Browser
• Change Browser Dimension
• Open New Tab
• Open New Window

Methods

driver.manage().window().maximize()
driver.manage().window().minimize()
driver.manage().window().fullscreen()
driver.manage().window().setSize(d)
driver.switchTo().newWindow(TAB)
driver.switchTo().newWindow(WINDOW)

🔧 Browser Dimension Example

Dimension d = new Dimension(1000, 400);
driver.manage().window().setSize(d);

Selenium Locators

8 Different Locators in Selenium

1. ID

Fastest locator in Selenium

By.id("elementId")

2. Name

By.name("elementName")

3. Class Name

By.className("className")

4. Tag Name

By.tagName("tagName")

5. Link Text

By.linkText("exactText")

6. Partial Link Text

By.partialLinkText("partialText")

7. CSS Selector

By.cssSelector("cssSelector")

8. XPath

By.xpath("xpathExpression")

CSS Selector vs XPath

CSS Selector

  • • Locate elements in forward direction only
  • • Uses ID, class name, tag name, and attributes
  • • Can locate shadow elements
  • • Generally faster performance
  • • Simpler syntax for basic selections

XPath

  • • Locate elements in forward and backward directions
  • • Uses text, contains(), starts-with(), following, preceding
  • • Cannot locate shadow elements
  • • More powerful for complex selections
  • • Supports parent, child, ancestor, descendant relationships

Important Method Differences

close() vs quit() Method

close() Method

  • • Closes focused window only
  • • Does not terminate the session
  • • Other windows remain open
  • • WebDriver instance still active

quit() Method

  • • Closes all windows and tabs
  • • Terminates the WebDriver session
  • • Releases system resources
  • • WebDriver instance becomes inactive

get() vs navigate().to() Method

get() Method

  • • Waits until all components are loaded
  • • Present in WebDriver interface
  • • Blocks until page is fully loaded
  • • Better for initial page loading

navigate().to() Method

  • • Does not wait for all components
  • • Present in Navigation interface
  • • Non-blocking navigation
  • • Better for quick navigation

Element Operations Summary

Text Box Operations

• isDisplayed() → boolean | isEnabled() → boolean
• sendKeys("value") → void | getAttribute("value") → String
• clear() → void

Radio Button & Checkbox Operations

• isDisplayed() → boolean | isEnabled() → boolean
• isSelected() → boolean | click() → void
• isSelected() → boolean (after click)

Button Operations

• isDisplayed() → boolean | isEnabled() → boolean
• click() → void
• getText() or getAttribute() → String (based on tagName)
• getCssValue("background-color") → String

Links & Images Operations

• isDisplayed() → boolean | isEnabled() → boolean
• click() → void (for clickable elements)
• getText() → String | getAttribute("href"/"src") → String

Assignments

Assignment 1: Browser Navigation

Tasks:

  • • Open a browser and maximize window
  • • Open Wikipedia URL
  • • Click on English Link
  • • Search "INDIA" and click search button
  • • Capture browser title and URL
  • • Navigate to RedBus application
  • • Refresh page, navigate back, navigate forward
  • • Close all windows and terminate session

Assignment 2: E-commerce Flow

URL: https://www.saucedemo.com/inventory.html

  • • Login to the application
  • • Select "Price (high to low)" sorting
  • • Click on first "Add to Cart" button
  • • Click on shopping cart container
  • • Click on "Checkout" button
  • • Enter first name, last name, and zip code
  • • Click on "Continue" button
  • • Click on "Finish" button

Day 15 Knowledge Check

Question 1 of 5

Which is the fastest locator in Selenium?

SDET Mastery

Master Test Automation

Home
CurriculumPracticeQ&ACheatsheet
🍵Buy me a Chai

Automation Testing Course

Comprehensive course covering Manual Testing, Java Programming, and Selenium WebDriver

🍵Buy me a Chai
Privacy Policy•GitHub
© 2024 Automation Testing Course. All rights reserved.