25 Selenium methods with Story telling!
3 min readApr 17, 2024
- WebDriver. get(String url): Our journey begins with this method, as it navigates the WebDriver to a specified URL, opening the door to our testing adventure.
- WebElement. sendKeys(CharSequence… keysToSend): Like a magician’s wand, this method sends a sequence of keystrokes to a web element, allowing us to interact with input fields and forms.
- WebElement. click(): With a simple click, this method triggers the element’s click event, enabling us to simulate user interactions like button clicks and links.
- WebElement. getText(): This method retrieves the visible inner text of the web element, providing us with valuable information for verification and assertion.
- WebDriver. findElement(By by): As our journey unfolds, this method finds the first web element within the current page using the given locator strategy.
- WebDriver. findElements(By by): Similar to the previous method, but it returns a list of all matching web elements, expanding our testing horizons to handle multiple elements.
- WebElement. getAttribute(String name): Like a treasure map, this method retrieves the value of the specified attribute of the web element, unlocking hidden insights.
- WebElement. isDisplayed(): With this method, we can determine if a web element is currently being displayed on the page, aiding in visibility checks during our testing quest.
- WebElement. isEnabled(): Much like a gatekeeper, this method verifies if the web element is currently enabled or not, helping us validate interactive elements’ states.
- WebElement. isSelected(): This method checks if a checkbox, radio button, or option in a dropdown menu is currently selected, guiding us in verifying user choices.
- WebDriver. navigate(). refresh(): When the need arises to refresh the current page, this method becomes our trusty companion, reloading the page and renewing our testing canvas.
- WebDriver. navigate(). to(String url): With this method, we can navigate to a new URL within the same browser window, exploring different regions of the web during our testing odyssey.
- WebDriver. switchTo(). alert(): When unexpected pop-up alerts appear, this method allows us to switch the WebDriver’s focus to the alert, enabling us to handle it gracefully.
- WebDriver. switchTo(). defaultContent(): Like a homing beacon, this method returns the WebDriver’s focus to the default content, ensuring we navigate back to familiar territory after handling iframes.
- WebDriver. switchTo(). frame(int index): With this method, we can switch the WebDriver’s focus to a specific iframe on the page, extending our reach to interact with embedded content.
- WebDriver. switchTo(). frame(String nameOrId): Similar to the previous method, but here we target the iframe by its name or ID attribute, offering flexibility in our testing strategy.
- WebDriver. switchTo(). window(String windowHandle): When multiple browser windows are open, this method allows us to switch the WebDriver’s focus to a specific window by its unique handle, enabling seamless testing across windows.
- WebDriver. manage(). window(). maximize(): Like expanding our view, this method maximizes the browser window, providing us with ample space to conduct our testing endeavors.
- WebDriver. manage(). timeouts(). implicitlyWait() : With this method, we can set a global timeout for the WebDriver to implicitly wait for elements to appear, enhancing stability and reliability in our tests.
- Actions. moveToElement(WebElement toElement): As if guided by intuition, this method moves the mouse cursor to the center of the specified web element, facilitating actions like hover and context menu interactions.
- Actions. clickAndHold(WebElement onElement): With a steady hand, this method clicks and holds the specified web element, paving the way for drag-and-drop operations and other complex interactions.
- Actions. release(): Like setting a bird free, this method releases the mouse button previously held down, concluding drag-and-drop operations and other mouse-related actions.
- Actions. keyDown(Keys theKey): When the need arises to simulate pressing a specific keyboard key, this method presses down the specified key, unlocking a world of keyboard-driven interactions in our testing journey.
- Actions. keyUp(Keys theKey): Similar to the previous method, but here we release the previously pressed key, ensuring precise control over keyboard interactions during our testing expedition.
- JavascriptExecutor. executeScript(String script, Object… args): Like casting a spell, this method executes JavaScript code within the context of the current page, offering unparalleled flexibility and power in our testing rituals.
Swaroop Nadella
Test Automation Engineer, Tech Educator
Subscribe here, to Get an email whenever I publish article on Medium
Core Java and Coding for Automation Testers — Udemy Course
Swaroop Nadella Academy Store — Quizzes and Courses