FullBasic to Advanced Selenium Cheat Sheet -1
FullBasic to Advanced Selenium Cheat Sheet -1
✅ 2. getTitle() 🏷️
Declared in: WebDriver interface
Arguments: None.
Arguments: None.
✅ 4. getCurrentUrl() 🔗
Declared in: WebDriver interface
Arguments: None.
✅ 5. getWindowHandle() 🖼️
Declared in: WebDriver interface
Arguments: None.
Purpose: Useful to get the handle value of the current browser window/tab.
✅ 6. getWindowHandles() 🖼️🖼️
Declared in: WebDriver interface
Arguments: None.
✅ 7. close() ❌
Declared in: WebDriver interface
Arguments: None.
Returns: void .
✅ 8. quit() 🚪
Declared in: WebDriver interface
Returns: void .
✅ 9. navigate() 🧭
Declared in: WebDriver interface
Arguments: None.
✅ 10. switchTo() 🔄
Declared in: WebDriver interface
Arguments: None.
Purpose: Useful to move the focus of the driver to a specific frame, alert, or
active element on the current page.
Purpose: Shifts the focus of the driver to a specific frame on the webpage.
Sub-Methods:
ii. switchTo().alert()
Actions on Alerts:
iii. switchTo().window()
Purpose: Switches the focus to a specific browser window or tab using its
handle.
Sub-Methods:
iv. switchTo().activeElement()
Method: driver.switchTo().activeElement()
v. driver.switchTo().newWindow(WindowType)
✅ 11. manage() ⚙️
Declared in: WebDriver interface
Arguments: None.
i. Cookies
Sub-Methods:
ii. Timeouts
Sub-Methods:
Sub-Methods:
Sub-Methods:
12. findElement(By) 🔍
Declared in: SearchContext interface
interface (inheritance).
By ID: driver.findElement(By.id("element_id"))
By Name: driver.findElement(By.name("element_name"))
By XPath: driver.findElement(By.xpath("xpath_expression"))
✅ 13. findElements(By) 🔍🔍
Declared in: SearchContext interface
interface (inheritance).
Returns: List<WebElement>
Purpose: Useful to locate and collect one or more matched elements in the
page source.
✅ 14. click() 🖱️
Declared in: WebElement interface
How to use: Use findElement() to locate an element, then invoke click() on that
element.
Arguments: None.
Returns: void .
✅ 15. sendKeys() ⌨️
Declared in: WebElement interface
How to use: Use findElement() to locate an input field, then invoke sendKeys() to
type text into it.
Arguments: Takes a String value that will be sent to the input element.
Returns: void .
✅ 16. clear() ✂️
Declared in: WebElement interface
How to use: Use findElement() to locate an input field, then invoke clear() to
clear the existing text in the field.
Arguments: None.
Returns: void .
✅ 17. isDisplayed() 👀
Declared in: WebElement interface
Arguments: None.
✅ 18. isEnabled() 💪
Declared in: WebElement interface
Arguments: None.
✅ 19. isSelected() ✅
Declared in: WebElement interface
Arguments: None.
✅ 20. getText() 📝
Declared in: WebElement interface
Arguments: None.
✅ 21. getAttribute() 🏷️
Declared in: WebElement interface
✅ 22. wait() ⏳
Beginner to Advanced Selenium Cheat Sheet: Your Ultimate Guide! 12
Declared in: WebDriverWait class
✅ 23. WebDriverException ⚠️
Declared in: WebDriverException class
Arguments: None.
try {
WebElement element = driver.findElement(By.id("nonExistentElement"));
} catch (WebDriverException e) {
System.out.println("Error encountered: " + e.getMessage());
}
✅ 24. Alert 🚨
Declared in: Alert interface
Arguments: None.
Purpose: Handle pop-up alert boxes (accept, dismiss, retrieve text, etc.).
✅Windows 🪟
25. Window Handles & Switching Between Multiple
How to use: Use getWindowHandles() to retrieve handles for all open windows
and switchTo().window() to switch between them.
Returns: void .
Purpose: This allows you to handle and switch between multiple browser
windows or tabs in Selenium.
How to use: Use Actions to simulate complex user interactions like mouse
movements, key presses, drag and drop, etc.
Arguments: Takes WebDriver object and the actions you want to perform.
Arguments: Takes WebDriver and Duration for timeouts and polling frequency.
Arguments: None.