Selenium-Java All Methods CheatSheet
1. WebDriver Interface Methods
| Method | Return Type | Description |
get(String url) | void | Opens a URL in the browser |
getCurrentUrl() | String | Returns the current page URL |
getTitle() | String | Returns the page title |
getPageSource() | String | Returns the HTML source of the page |
close() | void | Closes the current browser window |
quit() | void | Quits all browser windows and ends session |
getWindowHandle() | String | Returns the handle of the current window |
getWindowHandles() | Set<String> | Returns a set of all open window handles |
switchTo() | TargetLocator | Switches to frame, window, or alert |
navigate() | Navigation | Provides browser navigation options |
manage() | Options | Provides browser options like cookies, timeouts |
๐น 2. WebElement Interface Methods
| Method | Return Type | Description |
click() | void | Clicks the element |
submit() | void | Submits the form element |
sendKeys(CharSequence...) | void | Types into the element |
clear() | void | Clears the value of input field |
getTagName() | String | Gets the tag name of the element |
getAttribute(String name) | String | Gets the attribute value |
getText() | String | Gets the visible text |
getCssValue(String propertyName) | String | Gets CSS property value |
getLocation() | Point | Returns location of the element |
getSize() | Dimension | Gets size of the element |
getRect() | Rectangle | Gets dimensions and position |
isDisplayed() | boolean | Checks if visible |
isEnabled() | boolean | Checks if enabled |
isSelected() | boolean | Checks if selected |
findElement(By by) | WebElement | Finds child element |
findElements(By by) | List<WebElement> | Finds list of child elements |
๐น 3. Navigation Interface (from driver.navigate())
| Method | Return Type | Description |
to(String url) | void | Navigates to a URL |
to(URL url) | void | Navigates to a URL object |
back() | void | Navigates back in browser history |
forward() | void | Navigates forward |
refresh() | void | Reloads the current page |
๐น 4. TargetLocator Interface (from driver.switchTo())
| Method | Return Type | Description |
frame(int index) | WebDriver | Switch to frame by index |
frame(String nameOrId) | WebDriver | Switch to frame by name or ID |
frame(WebElement element) | WebDriver | Switch to frame by WebElement |
defaultContent() | WebDriver | Switch back to main frame |
parentFrame() | WebDriver | Switch to parent frame |
window(String nameOrHandle) | WebDriver | Switch to window |
alert() | Alert | Switch to alert popup |
activeElement() | WebElement | Switch to active element |
๐น 5. Alert Interface (JavaScript Alerts)
| Method | Return Type | Description |
accept() | void | Accepts alert |
dismiss() | void | Dismisses alert |
getText() | String | Gets alert text |
sendKeys(String keysToSend) | void | Sends input to alert |
๐น 6. Select Class (Dropdowns)
| Method | Return Type | Description |
selectByVisibleText(String text) | void | Select by visible option text |
selectByValue(String value) | void | Select by value attribute |
selectByIndex(int index) | void | Select by index |
deselectAll() | void | Deselects all options |
deselectByIndex(int index) | void | Deselect by index |
deselectByValue(String value) | void | Deselect by value |
deselectByVisibleText(String text) | void | Deselect by text |
getAllSelectedOptions() | List<WebElement> | Gets all selected options |
getFirstSelectedOption() | WebElement | Gets first selected option |
getOptions() | List<WebElement> | Gets all options in dropdown |
isMultiple() | boolean | Checks if multi-select |
๐น 7. Options Interface (from driver.manage())
| Method | Return Type | Description |
window() | Window | Returns window interface |
timeouts() | Timeouts | Returns timeouts interface |
deleteAllCookies() | void | Deletes all cookies |
addCookie(Cookie cookie) | void | Adds a cookie |
deleteCookieNamed(String name) | void | Deletes cookie by name |
getCookies() | Set<Cookie> | Gets all cookies |
getCookieNamed(String name) | Cookie | Gets cookie by name |
๐น 8. Timeouts Interface
| Method | Return Type | Description |
implicitlyWait(Duration duration) | Timeouts | Sets implicit wait |
pageLoadTimeout(Duration duration) | Timeouts | Sets max time for page load |
scriptTimeout(Duration duration) | Timeouts | Sets time for async script execution |
๐น 9. Actions Class (Mouse + Keyboard)
| Method | Return Type | Description |
click() | Actions | Clicks current mouse location |
click(WebElement element) | Actions | Clicks given element |
doubleClick() | Actions | Double-clicks |
contextClick() | Actions | Right-click |
moveToElement(WebElement element) | Actions | Move to element |
dragAndDrop(WebElement src, WebElement target) | Actions | Drags from source to target |
sendKeys(CharSequence keys) | Actions | Types keys |
keyDown(Keys key) | Actions | Holds down key |
keyUp(Keys key) | Actions | Releases key |
build() | Action | Builds the action chain |
perform() | void | Executes the action chain |