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

Software

The document outlines various methods for browser management, navigation, cookie management, window and frame management, wait and synchronization, alerts handling, and element interaction in web automation. Each method is described with its purpose and an example code snippet. These methods are essential for controlling browser actions and interacting with web elements in automated testing scenarios.

Uploaded by

ralom87276
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Software

The document outlines various methods for browser management, navigation, cookie management, window and frame management, wait and synchronization, alerts handling, and element interaction in web automation. Each method is described with its purpose and an example code snippet. These methods are essential for controlling browser actions and interacting with web elements in automated testing scenarios.

Uploaded by

ralom87276
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Browser Management Methods


These methods are used to control browser actions such as opening,
navigating, and closing.

Method Description Example

get(String Opens the specified URL in driver.get("https://


URL) the browser. example.com");

Returns the title of the


getTitle() String title = driver.getTitle();
current page as a String.

getCurrentUr Returns the URL of the String url =


l() current page. driver.getCurrentUrl();

getPageSour Returns the HTML source of String pageSource =


ce() the current page. driver.getPageSource();

Closes the current browser


close() driver.close();
window.

Closes all the browser


quit() windows opened by the driver.quit();
WebDriver instance.
2. Navigation Methods
Used for navigating through browser history or to a specific URL.
Method Description Example

navigate().to(Strin Navigates to a specified driver.navigate().to("https://


g URL) URL. example.com");

Moves to the previous


navigate().back() page in the browser driver.navigate().back();
history.

navigate().forward Moves to the next page in


driver.navigate().forward();
() the browser history.

navigate().refresh( Refreshes the current


driver.navigate().refresh();
) page.
7. Cookies Management Methods
Manage browser cookies.
Descriptio
Method Example
n

Retrieves all
cookies in Set<Cookie> cookies =
manage().getCookies()
the current driver.manage().getCookies();
session.

Adds a new
manage().addCookie(Cookie driver.manage().addCookie(new
cookie to
cookie) Cookie("key", "value"));
the browser.

Deletes a
manage().deleteCookieNamed(S specific driver.manage().deleteCookieNamed("
tring name) cookie by key");
name.

Deletes all
manage().deleteAllCookies() driver.manage().deleteAllCookies();
cookies.

4. Window and Frame Management Methods


Control browser windows, tabs, and frames.
Method Description Example

Returns the handle


String handle =
getWindowHandle() (ID) of the current
driver.getWindowHandle();
window.

Returns a set of
Set<String> handles =
getWindowHandles() handles for all open
driver.getWindowHandles();
browser windows.

Switches to a specific
switchTo().window(String
browser window driver.switchTo().window(handle);
handle)
using its handle.

switchTo().frame(int Switches to a frame


driver.switchTo().frame(0);
index) using its index.

switchTo().frame(String Switches to a frame driver.switchTo().frame("frameNam


nameOrId) using its name or ID. e");

Switches back to the


switchTo().defaultConten
main document from driver.switchTo().defaultContent();
t()
a frame.

5. Wait and Synchronization Methods


Used to handle dynamic content or delays in page loading.
Descri
Method Example
ption

Sets a
global
wait
time
manage().timeouts( driver.manage().timeouts().implicitlyWait(10,
for
).implicitlyWait() TimeUnit.SECONDS);
locatin
g
eleme
nts.

Waits
for
specifi
c
new WebDriverWait(driver,
Explicit Wait (via conditi
Duration.ofSeconds(10)).until(ExpectedConditions.visibi
WebDriverWait) ons to
lityOfElementLocated(By.id("elementId")));
be met
before
procee
ding.

6. Alerts Management Methods


Used for handling browser alerts or pop-ups.
Method Description Example

Alert alert =
switchTo().alert() Switches the context to the alert.
driver.switchTo().alert();

accept() Accepts the alert (OK button). alert.accept();

Dismisses the alert (Cancel


dismiss() alert.dismiss();
button).

Retrieves the text displayed in the String alertText =


getText()
alert. alert.getText();

sendKeys(String Sends text to the alert (if input is alert.sendKeys("Sample


text) allowed). input");

3. Element Interaction Methods


Used to locate and interact with web elements like clicking, typing, or retrieving
attributes.
Method Description Example

WebElement element =
findElement(By Locates a single web
driver.findElement(By.id("username"))
locator) element on the page.
;

Locates multiple web


findElements(By List<WebElement> elements =
elements on the page
locator) driver.findElements(By.tagName("a"));
and returns a list.

sendKeys(String Types the specified value


element.sendKeys("Hello");
value) into an input field.

Clicks on a web element,


click() element.click();
such as a button or link.

Retrieves the visible text


getText() String text = element.getText();
of a web element.

Retrieves the value of a


getAttribute(String String value =
specified attribute from a
attributeName) element.getAttribute("href");
web element.

Retrieves the CSS


getCssValue(String String color =
property value of a web
propertyName) element.getCssValue("color");
element.

Checks if the web


boolean visible =
isDisplayed() element is visible on the
element.isDisplayed();
page.

Checks if the web


boolean enabled =
isEnabled() element is enabled for
element.isEnabled();
interaction.

Checks if the web


element is selected boolean selected =
isSelected()
(useful for element.isSelected();
checkboxes/radios).

Clears the content of an


clear() element.clear();
input field.

You might also like