Navigation |
|
|
get(url) |
Loads a web page with the given URL. |
driver.get("https://www.example.com") |
navigate().to(url) |
Loads a web page with the given URL. |
driver.navigate().to("https://www.example.com") |
Element Identification |
|
|
findElement(by) |
Locates the first element matching the specified locator strategy. |
WebElement element = driver.findElement(By.id("username")) |
findElements(by) |
Locates all elements matching the specified locator strategy. |
List<WebElement> elements = driver.findElements(By.tagName("a")) |
Element Interactions |
|
|
click() |
Clicks on the element. |
element.click() |
sendKeys(text) |
Enters text into an input field or text area. |
element.sendKeys("Hello, World!") |
getText() |
Retrieves the visible text of an element. |
String text = element.getText() |
Assertions and Verifications |
|
|
assertEquals(expected, actual) |
Asserts that two values are equal. |
assertEquals("Title", driver.getTitle()) |
assertTrue(condition) |
Asserts that a condition is true. |
assertTrue(element.isDisplayed()) |
Wait and Synchronization |
|
|
implicitlyWait(timeout, unit) |
Sets a default waiting time for the element to appear. |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS) |
WebDriverWait |
Waits for a specific condition before proceeding. |
WebDriverWait wait = new WebDriverWait(driver, 10) |
Browser Manipulation |
|
|
switchTo().frame(name) |
Switches the focus to a frame with the specified name or index. |
driver.switchTo().frame("frameName") |
getWindowHandle() |
Retrieves the unique identifier of the current browser window. |
String windowHandle = driver.getWindowHandle() |
Browser Navigation |
|
|
navigate().back() |
Navigates the browser back to the previous page. |
driver.navigate().back() |
navigate().forward() |
Navigates the browser forward to the next page. |
driver.navigate().forward() |
Browser Actions |
|
|
sendKeys(Keys.RETURN) |
Sends the Enter/Return key to the browser. |
element.sendKeys(Keys.RETURN) |
Actions |
Performs advanced user interactions using the Actions class. |
Actions actions = new Actions(driver) |