0% found this document useful (0 votes)
9 views12 pages

Selenium Webdriver Commands

The document provides a comprehensive list of Selenium WebDriver commands categorized into various types such as Browser Commands, Navigation Commands, and Element Interaction Commands. It details frequently used commands for each category, including examples for actions like clicking, navigating, handling alerts, and managing cookies. Additionally, it covers commands for handling multiple windows, frames, and waits, as well as commands for file uploads and downloads.

Uploaded by

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

Selenium Webdriver Commands

The document provides a comprehensive list of Selenium WebDriver commands categorized into various types such as Browser Commands, Navigation Commands, and Element Interaction Commands. It details frequently used commands for each category, including examples for actions like clicking, navigating, handling alerts, and managing cookies. Additionally, it covers commands for handling multiple windows, frames, and waits, as well as commands for file uploads and downloads.

Uploaded by

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

SELENIUM WEBDRIVER COMMANDS (PART 01)

Here is the complete list of Selenium commands:

1. Browser Commands
2. Navigation Commands
3. Element Interaction Commands
4. Wait Commands
5. Alert Commands
6. Window Handling Commands
7. Frame Handling Commands
8. Action Commands
9. Cookie Commands
10. Screenshot Commands
11. Dropdown Handling Commands
12. Keyboard Events Commands
13. Mouse Events Commands
14. Multiple Window Handling Commands
15. Logging Commands

Here are the most important and frequently used Browser Commands in
Selenium:

 get(String url) – Opens the specified URL in the browser.


 getTitle() – Fetches the title of the current webpage.
 getCurrentUrl() – Retrieves the URL of the current page.
 close() – Closes the current browser window.
 quit() – Closes all browser windows opened by WebDriver and ends the session.
 navigate().to(String url) – Navigates to a specific URL.
 navigate().back() – Moves back to the previous webpage in the browser history.
 navigate().forward() – Moves forward to the next webpage in the browser history.
 navigate().refresh() – Refreshes the current webpage.
 manage().window().maximize() – Maximizes the current browser window.
 manage().window().minimize() – Minimizes the current browser window.
 manage().window().fullscreen() – Puts the browser in fullscreen mode.
 manage().deleteAllCookies() – Deletes all cookies in the current session.
 manage().timeouts().implicitlyWait(long time, TimeUnit unit) – Sets the default wait
time for finding elements.

PDF prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 01)

Here are the most important and frequently used Action Commands in Selenium:

 clickAndHold() – Clicks and holds the mouse button on a web element.


 moveToElement(WebElement target) – Moves the mouse to the center of the
specified web element.
 release() – Releases the mouse button after a click and hold action.
 doubleClick() – Double-clicks on a web element.
 dragAndDrop(WebElement source, WebElement target) – Drags a web element from
the source and drops it onto the target.

Here are the most important and frequently used Cookie Commands in Selenium:

 addCookie(Cookie cookie) – Adds a cookie to the current session.


 getCookieNamed(String name) – Retrieves a cookie by its name.
 getCookies() – Retrieves all cookies for the current session.
 deleteCookie(Cookie cookie) – Deletes the specified cookie.
 deleteCookieNamed(String name) – Deletes a cookie by its name.
 deleteAllCookies() – Deletes all cookies for the current session.

Here are the most important and frequently used Screenshot Commands in
Selenium:

 getScreenshotAs(OutputType<T> target) – Takes a screenshot of the current


window and returns it in the specified format.
 getScreenshotAs(FileOutputType file) – Saves the screenshot to a file in the specified
format.

PDF prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 01)

Here are the most important and frequently used Dropdown Handling Commands
in Selenium:

 selectByVisibleText(String text) – Selects an option from a dropdown based on the


visible text.
 selectByValue(String value) – Selects an option from a dropdown based on the value
attribute.
 selectByIndex(int index) – Selects an option from a dropdown based on its index.
 getFirstSelectedOption() – Retrieves the currently selected option in a dropdown.
 getAllSelectedOptions() – Retrieves all selected options in a multi-select dropdown.
 deselectByVisibleText(String text) – Deselects an option based on the visible text in
a multi-select dropdown.

Here are the most important and frequently used Keyboard Events Commands in
Selenium:

 sendKeys(CharSequence... keysToSend) – Sends specified keys to a web element.


 keyDown(Keys key) – Presses and holds the specified key.
 keyUp(Keys key) – Releases the specified key.

Here are the most important and frequently used Mouse Events Commands in
Selenium:

 click() – Clicks on a web element.


 contextClick() – Performs a right-click on a web element.
 doubleClick() – Double-clicks on a web element.
 moveToElement(WebElement target) – Moves the mouse to the center of the
specified web element.
 dragAndDrop(WebElement source, WebElement target) – Drags an element from
the source and drops it onto the target.

PDF prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 01)

Here are the most important and frequently used Multiple Window Handling
Commands in Selenium:

 getWindowHandles() – Retrieves a set of window handles for all open windows.


 switchTo().window(String windowHandle) – Switches the focus to the specified
window using its handle.
 close() – Closes the current window.
 switchTo().defaultContent() – Switches the focus back to the main document from
an iframe or frame.

Here are the most important and frequently used Logging Commands in
Selenium:

 getLog(String logType) – Retrieves logs of the specified type.


 manage().logs() – Manages the logs for the current session.
 getAvailableLogTypes() – Retrieves the available log types for the current driver.

Here are the most important and frequently used Navigation Commands in
Selenium:

 navigate().to(String url) – Navigates to a specific URL.


 navigate().back() – Moves back to the previous webpage in the browser history.
 navigate().forward() – Moves forward to the next webpage in the browser history.
 navigate().refresh() – Refreshes the current webpage.
 navigate().to(String url) – Navigates to the specified URL.
 manage().window().setPosition(Point p) – Sets the position of the current window.
 manage().window().setSize(Dimension d) – Sets the size of the current window.

PDF prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 01)

Here are the most important and frequently used Element Interaction Commands
in Selenium:

 findElement(By locator) – Finds the first web element matching the given locator.
 findElements(By locator) – Finds all web elements matching the given locator.
 click() – Clicks on the web element.
 sendKeys(CharSequence... keysToSend) – Sends the specified keys to the web
element.
 clear() – Clears the text from the web element.
 getText() – Retrieves the visible text of the web element.
 getAttribute(String name) – Retrieves the value of the specified attribute of the web
element.
 isDisplayed() – Checks if the web element is visible on the page.
 isEnabled() – Checks if the web element is enabled.
 isSelected() – Checks if the web element is selected
(useful for checkboxes and radio buttons).
 submit() – Submits the form associated with the web element.
 getCssValue(String propertyName) – Retrieves the value of the specified CSS
property of the web element.

Here are the most important and frequently used Wait Commands in Selenium:

 implicitlyWait(long time, TimeUnit unit) – Sets the default wait time for finding
elements.
 WebDriverWait(driver, Duration duration) – Creates an explicit wait instance for the
specified duration.
 until(ExpectedCondition<T> condition) – Waits until the specified condition is met.
 setScriptTimeout(long time, TimeUnit unit) – Sets the maximum time to wait for an
asynchronous script to finish executing.
 setPageLoadTimeout(long time, TimeUnit unit) – Sets the maximum time to wait for
a page to load completely.
 fluentWait(By locator, long timeout, long pollingTime) – Waits for a specified
condition while ignoring specific exceptions during the polling interval.

PDF prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 01)

Here are the most important and frequently used Alert Commands in Selenium:

 switchTo().alert() – Switches the focus to the currently active alert.


 accept() – Accepts the alert, similar to clicking the "OK" button.
 dismiss() – Dismisses the alert, similar to clicking the "Cancel" button.
 getText() – Retrieves the text displayed on the alert.
 sendKeys(String keysToSend) – Sends specified keys to the alert input field (if
available).
 isDisplayed() – Checks if the alert is currently displayed.

Here are the most important and frequently used Window Handling Commands in
Selenium:

 getWindowHandle() – Retrieves the window handle of the current window.


 getWindowHandles() – Retrieves a set of window handles for all open windows.
 switchTo().window(String windowHandle) – Switches the focus to the specified
window using its handle.
 close() – Closes the current window.
 switchTo().defaultContent() – Switches the focus back to the main document from
an iframe or frame.
 switchTo().parentFrame() – Switches the focus to the parent frame of the current
frame.

Here are the most important and frequently used Frame Handling Commands in
Selenium:

 switchTo().frame(int index) – Switches the focus to the frame at the specified index.
 switchTo().frame(String nameOrId) – Switches the focus to the frame using its name
or ID.
 switchTo().frame(WebElement frameElement) – Switches the focus to the specified
frame element.
 switchTo().defaultContent() – Switches the focus back to the main document from a
frame.
 switchTo().parentFrame() – Switches the focus to the parent frame of the current
frame.

PDF prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 02)

Here is the complete list of Selenium commands:

 Session Handling Commands


 JavaScript Execution Commands
 Drag and Drop Commands
 File Upload Commands
 File Download Commands
 Popup Handling Commands
 Browser Tab Handling Commands
 Implicit Wait Commands
 Explicit Wait Commands
 Fluent Wait Commands
 Context Menu Commands
 Web Element Property Commands
 Navigation Bar Handling Commands
 JavaScript Alerts Handling Commands
 Page Source Commands

Here are the most important and frequently used Session Handling Commands in
Selenium:

 driver.getSessionId(): Retrieves the session ID of the current WebDriver session,


which is unique for each browser session.
 driver.quit(): Ends the current WebDriver session and closes all browser windows
associated with it.
 driver.close(): Closes the current active browser window, but the session will
continue if there are other open windows.
 driver.getWindowHandle(): Retrieves the current window handle, which is useful
when switching between multiple browser windows or tabs.
 driver.getWindowHandles(): Retrieves a set of all window handles of the current
session, useful for managing multiple browser windows or tabs.

PDF Prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 02)

Here are the most important and frequently used JavaScript Execution Commands
in Selenium:

 JavascriptExecutor js = (JavascriptExecutor) driver;


js.executeScript("arguments[0].click();", element); > Executes JavaScript code to
perform a click on an element, bypassing traditional WebDriver click().
 js.executeScript("window.scrollBy(0,1000);"); > Scrolls down the webpage by
the specified pixel amount.
 js.executeScript("return document.title;"); > Executes JavaScript to retrieve the
page title.
 js.executeScript("arguments[0].scrollIntoView(true);", element); > Scrolls the
page until the specified element is visible.
 js.executeScript("return document.readyState;").equals("complete"); >
Executes JavaScript to check if the page has completely loaded.

Here are the most important and frequently used Drag and Drop Commands in
Selenium:

 Actions actions = new Actions(driver); actions.dragAndDrop(sourceElement,


targetElement).perform(); > Performs drag and drop from the source element to
the target element.
 actions.clickAndHold(sourceElement).moveToElement(targetElement).releas
e().perform(); > Clicks, holds the source element, moves it to the target element,
and releases it.

Here are the most important and frequently used File Upload Commands in
Selenium:

 WebElement uploadElement = driver.findElement(By.id("uploadFile"));


uploadElement.sendKeys("C:\\path\\to\\file"); > Uploads a file by sending the
file path to the input element.
 driver.findElement(By.name("upload")).sendKeys("/path/to/file"); > Another
way to upload a file by providing the full file path to an input element.

PDF Prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 02)

Here are the most important and frequently used File Download Commands in
Selenium:

 For Chrome:
ChromeOptions options = new ChromeOptions();
options.addArguments("download.default_directory", "/path/to/download");
> Sets the default directory for file downloads in Chrome.
 For Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "/path/to/download"); >
Configures the download directory for Firefox.
 For more complex scenarios, you may need to integrate third-party libraries to
handle file downloads.

Here are the most important and frequently used Popup Handling Commands in
Selenium:

 driver.switchTo().alert().accept(); > Accepts the popup alert (similar to clicking


'OK').
 driver.switchTo().alert().dismiss(); > Dismisses the popup alert (similar to
clicking 'Cancel').
 driver.switchTo().alert().getText(); > Retrieves the text displayed in the popup
alert.
 driver.switchTo().alert().sendKeys("text"); > Sends text input to a prompt-style
alert.

PDF Prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 02)

Here are the most important and frequently used Browser Tab Handling
Commands in Selenium:

 String currentTab = driver.getWindowHandle(); > Retrieves the current browser


tab's handle.
 Set<String> allTabs = driver.getWindowHandles(); > Retrieves the handles of all
open browser tabs.
 driver.switchTo().window(tabHandle); > Switches to the specified browser tab
using its handle.
 driver.close(); driver.switchTo().window(parentHandle); > Closes the current
tab and switches back to the parent window.

Here are the most important and frequently used Implicit Wait Commands in
Selenium:

 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); > Sets a


global implicit wait for 10 seconds, instructing WebDriver to wait before throwing
an exception if the element is not found.

Here are the most important and frequently used Explicit Wait Commands in
Selenium:

 WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")
)); > Waits explicitly for the element to be visible within a 10-second window.
 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button")));
> Waits for the element to be clickable.

PDF Prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 02)

Here are the most important and frequently used Fluent Wait Commands in
Selenium:

 Wait<WebDriver> wait = new


FluentWait<>(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Du
ration.ofSeconds(5)).ignoring(NoSuchElementException.class); > Configures a
fluent wait with a timeout of 30 seconds, polling every 5 seconds, ignoring
NoSuchElementException.

Here are the most important and frequently used Context Menu Commands in
Selenium:

 Actions actions = new Actions(driver);


actions.contextClick(element).perform(); > Performs a right-click on the given
element to trigger the context menu.

Here are the most important and frequently used Web Element Property
Commands in Selenium:

 String text = element.getText(); > Retrieves the visible text of the web element.
 String attribute = element.getAttribute("value"); > Retrieves the value of a
specific attribute of the web element.
 boolean isDisplayed = element.isDisplayed(); > Checks whether the element is
visible.
 boolean isEnabled = element.isEnabled(); > Checks whether the element is
enabled for interaction.
 boolean isSelected = element.isSelected(); > Checks whether the element (like a
checkbox) is selected.

PDF Prepared by Ram Sharan Follow me on LinkedIN


SELENIUM WEBDRIVER COMMANDS (PART 02)

Here are the most important and frequently used Navigation Bar Handling
Commands in Selenium:

 driver.navigate().to("https://example.com"); > Navigates to the specified URL.


 driver.navigate().back(); > Moves back to the previous page in the browser
history.
 driver.navigate().forward(); > Moves forward to the next page in the browser
history.
 driver.navigate().refresh(); > Refreshes the current page.

Here are the most important and frequently used JavaScript Alerts Handling
Commands in Selenium:

 driver.switchTo().alert().getText(); > Retrieves the text from a JavaScript alert.


 driver.switchTo().alert().accept(); > Accepts the JavaScript alert (clicks 'OK').
 driver.switchTo().alert().dismiss(); > Dismisses the JavaScript alert (clicks
'Cancel').
 driver.switchTo().alert().sendKeys("input text"); > Sends text to a prompt alert
box.

Here are the most important and frequently used Page Source Commands in
Selenium:

 String pageSource = driver.getPageSource(); > Retrieves the entire source code


of the current webpage.

PDF Prepared by Ram Sharan Follow me on LinkedIN

You might also like