Top Selenium Commands for Developers and Testers
Related Product On This Page What are Selenium Commands?February 10, 2026 · 14 min read · Tool Comparison
Selenium commands help automatize browser activeness and test web applications efficiently. They form the foundation of any Selenium script, enabling developers and testers to feign user interactions and validate functionality. What are Selenium Commands? Selenium commands are methods provided by the Selenium WebDriver API to perform tasks like clicking elements, entering text, navigating Page, and verifying weather in a web browser. Top Selenium Commands Mastering these essential commands can greatly raise the speed and reliability of your test automation. This article explains what Selenium commands are and highlights the most usually used ones that are crucial for building efficacious automated exam playscript. commandsrefer to the predefined methods (such as getTitle (), getCurrentUrl (), click (), and more) provided by Selenium WebDriver that enables interaction with web element and control browser behavior during. These commands help automatize respective browser tasks, such as navigating between tabloid and windows, tick on buttons or other elements, getting the current page rubric or URL, entering textbook in the text box, and many more. These methods are accessed by apply a driver aim and telephonedriver.methodName (). Also Read: Examples: Browser commands provide control over the browser ’ s actions, which include open a browser, perform activeness on a web browsing, r and closing it. These include launching a web page, fetching page title, page URL, rootage URL, shut the web page/ browser, etc. 1. Get command: This method loads a new web page in the live browser window, accepting a String as a argument and returning nullity. Syntax: 2. Get rubric command: This method fetches the rubric of the current web page, direct no argument, and returns a String. Syntax: Example: 3. Get current URL command: This command fetch the URL of the current web page, conduct no parameters, and returns a String. Syntax: Example: 4. Get page source command: This command fetches the seed code of the current web page on the current web browser. It conduct no parameter and returns a String. Syntax: Example: 5. Close dictation: This method closes the current web page that the driver is pointing to on the current browser window. If the current web page is the only browser window, it also terminates the browser window. Syntax: Example: 6. Quit command: This method terminates all the windows run by the WebDriver. It accepts no parameter and returns void. Syntax: Example: Navigational commands facilitate perform operation that involve navigating through web Page. They also expeditiously grapple a browser ’ s history and do actions like going back, forward, and review the current page. 1. Navigate To require: This method charge a new page in the existing browser window, takes a String as a parameter, and return void. Syntax: Example: 2. Forward command: This method enable the web browser to click on the forward button in the subsist browser window. It accepts no parameter and returns vacancy. Syntax: Example: 3. Back command: This method enable the web browser to chatter on the back button in the existing browser window. It accepts no parameter and returns void. Syntax: Example: 4. Refresh command: This method refreshes the current web page in the existing web browser window. It consent no parameter and returns nothingness. Syntax: Example: A web element is an HTML component that contains a start and end tag and the substance in between. Selenium cater a way to interact with all the web elements present on the web page with the help of web element commands. Actions such as sending keys, snap on a push, reading text value, checking-unchecking radio buttons, selecting from a drop-down push, etc. can be performed with. Some of the Webelement bidding are as follows: 1. Click command: This method do click operation on a web element. Syntax: Example: 2. SendKeys command: This method enters text into the editable battlefield and guide a String as a argument. Syntax: Example: 3. Clear command: This command is used to clear the text area & # 8217; s content. It takes no argument and return void. Syntax: Example: 4. Get text command: This method is used to regain the inner text of the web factor, which CSS do not hide. It occupy no parameter and returns a String. Syntax: Example: 5. Get Attribute bid: This method retrieves the value of a specified attribute of a web factor. It takes a String as a parameter and returns a String. Syntax: Example: 6. Get Location bid: This method retrieves the location of a specific web element on the web page in terms of X and Y coordinates. Syntax: Example: 7. Get CSS Value command: This method fetches the CSS property value of the given web ingredient. It takes no parameter and returns a String value. Syntax: Example: 8. Is Enabled command: This command is used to control if a particular web constituent is enable on the web page. It returns a boolean true value if the constituent is enabled or false if it is not enable. Syntax: Example: 9. Is Selected command: This command is habituate to control if a especial web element, such as wireless or checkbo, x is select or not. It returns a boolean true value if the element is selected or false if it is not choose. Syntax: Example: 10. Is Displayed command: This command is used to verify if a particular web ingredient is visible on the web page. It returns a boolean true value if the element is expose or false if it is not displayed. Syntax: Example: Radio button let a user select but one selection from a group, while checkboxes allow choose one or more pick. In Selenium, you can chatter these elements, deselect them when needed, and confirm if an option is selected. These commands make it easy to work with radio push and checkboxes in forms and test their behavior. 1. Click Command This method is used to select a radio button or a checkbox. Syntax: Example: 2. isSelected Command This method verifies if a radio button or checkbox is selected. It returns a boolean value — true if selected and false if not. Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Syntax: Example: 3. isEnabled Command This method verifies if a radio push or checkbox is enable and can be interact with. Syntax: Example: Dropdowns let exploiter select an option from a list. They are used when a form has fixed pick, such as a nation, province, or category. Buttons execute an action when clicked and can be used to subject a variety, add an item to a cart, or displace to the next page. Selenium furnish methods for selecting options from a dropdown menu and clicking on button. These bid help you mimic user behavior and confirm that descriptor, searches, and former interactional element work as expected. 1. Click Command (Button) This method is expend to click a button element. It spark the activeness associated with the button, like submitting a form or opening a menu. Syntax: Example: 2. Quality Command (Dropdown) The Select class in Selenium is apply to act with & lt; select & gt; elements. It provides methods to prefer alternative by visible text, value, or index. Syntax: Example: 3. Get Selected Option Command (Dropdown) This method retrovert the first selected option in the dropdown. Syntax: Example: Modern web applications often open links or results in new windows or tabs. In Selenium, you can switch between window and chit using built-in methods. These methods help manage multiple pages, making it easy to test scenarios like verifying a link in a new tab or elicit information from a pop‑up window. 1. Get Window Handle Command This method returns the unique identifier of the current window. Syntax: Example: 2. Get Window Handles Command This method returns the identifiers of all open window or tabloid. Syntax: Example: 3. Switch To Window Command This method switches the direction of the driver to a specific window or tab. Syntax: Example: 4. Close Command This method closes the current window. Syntax: Example: Frames and iFrames engraft another HTML page within a page. In Selenium, you can exchange to a frame or iFrame before working with its elements. These commands help move in and out of frames, making locating and testing ingredient inside them easy. 1. Switch to Frame by Index Switches the focusing to a frame or iFrame based on its position. Syntax: Example: 2. Switch to Frame by Name or ID Switches the focus to a frame or iFrame use its name or ID attribute. Syntax: Example: 3. Switch to Frame by Web Element Switches the focusing to a bod apply its WebElement. Syntax: Example: 4. Switch Back to Main Page Switches the focus from a frame or iFrame back to the main page. Syntax: Example: Read More: The Actions class in Selenium is used for complex user interactions, such as mouse movements, drag and drop, right clink, and double clicks. These commands help assume advanced behaviour that goes beyond basic clicks and typing. 1. Mouse Hover Command Moves the mouse arrow over a specific element. Syntax: Example: 2. Drag and Drop Command Drags an element and drops it to a mark location. Syntax: Example: 3. Right Click Command Performs a right click on an element. Syntax: Example: 4. Double-Click Command Performs a threefold click on an element. Syntax: Example: handgrip delays and ensure factor are available before interaction. These commands help you pen stable and reliable test scripts. 1. Implicit Wait Command Adds a wait time for finding elements. The driver will canvas the page until the element is found or the time croak. Syntax: Example: 2. Explicit Wait Command Waits for a specific condition, like an element being visible or clickable. Syntax: Example: 3. Fluent Wait Command Waits for an component with polling at regular interval and can ignore certain exception. Syntax: Example: Selenium 4 introduced new commands and improved characteristic that make exam automation more flexible. These include for finding elements establish on their position congenator to former components. This makes it easy to progress test playscript that are both reliable and readable. 1. Relative Locators Selenium 4 added to locate element based on their position in copulation to early elements. This makes it uncomplicated to build robust locators when fixed identifiers aren ’ t available. Syntax: Syntax: Syntax: Syntax: Syntax: 2. New Window Command Selenium 4 introduced a elementary method for opening and managing new windows or tabs. Syntax: Example: 3. New Get Element Screenshot Command Selenium 4 allows capturing a screenshot of a specific element, make it easy to formalise or document event. Syntax: Example: BrowserStack is a testing platform that provides thousands of existent devices and browsers, advanced debugging tools, and unlined automation support. This allows you to run your Selenium scripts exactly as they would run in the hands of a existent user, spot issues betimes, and release better package. Here are some key features of: Selenium require define how scripts locate elements, simulate user interactions, navigate between Page, and validate behavior across different browser. Understanding these commands yield testers precise control over the flow of machine-driven examination and countenance them to cover a wide range of scenario. provide the environment where you can quiz these commands. It hosts an all-inclusive scope of devices, support parallel execution, and captures detailed logs, screenshots, and recordings for every test run. Methods, Classes, and Commands Configuration XPath Locators and Selectors Waits in Selenium Frameworks in Selenium Miscellaneous Best Practices, Tips and Tricks Design Patterns in Selenium: Page Object Model and Page Factory Action Class TestNG and Selenium JUnit and Selenium Use Cases Types of Testing with Selenium On This Page # Ask-and-Contributeabout this issue with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
Top Selenium Commands for Developers and Testers
Overview
What are Selenium Commands?
driver.get (“ https: //www.browserstack.com ”); driver.switchTo () .frame (1);
Browser Commands in Selenium
get (String URL)
getTitle ()
String title=driver.getTitle ();
getCurrentUrl ()
String URL=driver. getCurrentUrl ();
getPageSource ()
String pageSource=driver. getPageSource ();
close()
driver.close ();
quit()
driver. quit ();
Navigational Commands in Selenium
navigate () .to (String URL)
driver.navigate () .to (“ https: //www.browserstack.com ”);
navigate () .forward ()
driver.navigate () .forward ();
navigate () .back ()
driver.navigate () .back ();
navigate () .refresh ()
driver.navigate () .refresh ();
WebElement Commands in Selenium
click()
WebElement ele=driver.findElement (By.id (“ locator id ”)); ele.click ();
sendKeys (String schoolbook)
WebElement ele=driver.findElement (By.id (“ textbox id ”)); ele.sendKeys (“ Hello ”);
clear()
WebElement ele=driver.findElement (By.id (“ textbox id ”)); ele.sendKeys (“ Hello ”); ele.clear ();
getText()
WebElement ele=driver.findElement (By.id (“ textbox id ”)); String text= ele. getText ();
getAttribute (String attribute)
WebElement ele=driver.findElement (By.id (“ textbox id ”)); String value = ele. getAttribute (“ id ”); // Returns the “ id ” attribute
getLocation ()
WebElement ele=driver.findElement (By.id (“ textbox id ”)); Point point = ele. getLocation (); System.out.println (`` X cordinate: `` + point.x + `` Y cordinate: `` + point.y);
getCssValue ()
WebElement ele=driver.findElement (By.id (“ textbox id ”)); String cssValue= ele.getCssValue ();
isEnabled ()
WebElement ele=driver.findElement (By.id (“ textbox id ”)); boolean iris = ele. isEnabled ();
IsSelected ()
WebElement ele=driver.findElement (By.id (“ textbox id ”)); boolean flag = ele. IsSelected ();
isDisplayed ()
WebElement ele=driver.findElement (By.id (“ textbox id ”)); boolean flag = ele.isDisplayed ();
Radio Button and Check Box Commands
click()
WebElement radioButton = driver.findElement (By.id (`` radioOption '')); radioButton.click ();
isSelected ()
WebElement radioButton = driver.findElement (By.id (`` radioOption '')); boolean isChecked = radioButton.isSelected ();
isEnabled ()
WebElement radioButton = driver.findElement (By.id (`` radioOption '')); boolean isEnabled = radioButton.isEnabled ();
Dropdown and Button Commands
click()
WebElement submitButton = driver.findElement (By.id (`` submitBtn '')); submitButton.click ();
Select select = new Select (driver.findElement (By.id (`` dropdownId ''))); select.selectByVisibleText (`` Option Text ''); select.selectByValue (`` optionValue ''); select.selectByIndex (2);
WebElement dropDown = driver.findElement (By.id (`` country '')); Select take = new Select (dropDown); // Select by visible text select.selectByVisibleText (`` Canada ''); // Select by value select.selectByValue (`` ca ''); // Select by index select.selectByIndex (3);
getFirstSelectedOption ()
WebElement dropDown = driver.findElement (By.id (`` commonwealth '')); Select select = new Select (dropDown); WebElement selectedOption = select.getFirstSelectedOption (); String optionText = selectedOption.getText ();
Window and Tab Handling Commands
getWindowHandle ()
String mainWindow = driver.getWindowHandle ();
getWindowHandles ()
Set & lt; String & gt; allWindows = driver.getWindowHandles ();
switchTo () .window (windowHandle)
for (String handle: allWindows) {driver.switchTo () .window (handle);}close()
driver.close ();
Frame and iFrame Commands
switchTo () .frame (power)
// Switch to the second frame on the page driver.switchTo () .frame (1); // Now you can locate elements within that frame WebElement form = driver.findElement (By.id (`` signupForm ''));
switchTo () .frame (`` frameName '');
// Switch to the frame with the id `` paymentFrame '' driver.switchTo () .frame (`` paymentFrame ''); // Enter card details driver.findElement (By.name (`` cardNumber '')) .sendKeys (`` 4111111111111111 '');
switchTo () .frame (WebElement element)
WebElement frame = driver.findElement (By.id (`` iframe '')); driver.switchTo () .frame (frame);
switchTo () .defaultContent ()
// Switch back to the main page after work in a frame driver.switchTo () .defaultContent (); // Now you can place factor in the main page WebElement card = driver.findElement (By.id (`` mainMenu '')); menu.click ();
Actions Class Commands
moveToElement (WebElement element)
WebElement menu = driver.findElement (By.id (`` menu '')); Actions action = new Actions (driver); action.moveToElement (menu) .perform ();
dragAndDrop (WebElement seed, WebElement mark)
WebElement origin = driver.findElement (By.id (`` source '')); WebElement target = driver.findElement (By.id (`` target '')); new Actions (driver) .dragAndDrop (source, prey) .perform ();
contextClick (WebElement element)
WebElement ingredient = driver.findElement (By.id (`` factor '')); new Actions (driver) .contextClick (ingredient) .perform ();
doubleClick (WebElement factor)
WebElement constituent = driver.findElement (By.id (`` ingredient '')); new Actions (driver) .doubleClick (element) .perform ();
Synchronization and Wait Commands
driver.manage () .timeouts () .implicitlyWait (Duration.ofSeconds (10));
// Set implicit hold to 10 seconds driver.manage () .timeouts () .implicitlyWait (Duration.ofSeconds (10)); // Now any element search will wait up to 10 seconds WebElement constituent = driver.findElement (By.id (`` elementId ''));
WebDriverWait wait = new WebDriverWait (driver, Duration.ofSeconds (10)); wait.until (ExpectedConditions.visibilityOfElementLocated (By.id (`` elementId '')));
WebDriverWait wait = new WebDriverWait (driver, Duration.ofSeconds (10)); // Wait until the login push is visible WebElement loginButton = wait.until (ExpectedConditions.visibilityOfElementLocated (By.id (`` loginButton ''))); // Click the button once it 's visible loginButton.click ();
Wait & lt; WebDriver & gt; wait = new FluentWait & lt; & gt; (driver) .withTimeout (Duration.ofSeconds (30)) .pollingEvery (Duration.ofSeconds (5)) .ignoring (NoSuchElementException.class);
WebElement element = wait.until (driver - & gt; driver.findElement (By.id (`` elementId '')));
New Features and Commands in Selenium 4
WebElement elem = driver.findElement (By.id (`` elementId '')); WebElement aboveElement = driver.findElement (withTagName (`` div '') .above (elem));
WebElement elem = driver.findElement (By.id (`` elementId '')); WebElement belowElement = driver.findElement (withTagName (`` div '') .below (elem));
WebElement elem = driver.findElement (By.id (`` elementId '')); WebElement leftElement = driver.findElement (withTagName (`` div '') .toLeftOf (elem));
WebElement elem = driver.findElement (By.id (`` elementId '')); WebElement rightElement = driver.findElement (withTagName (`` div '') .toRightOf (elem));
WebElement elem = driver.findElement (By.id (`` elementId '')); WebElement nearElement = driver.findElement (withTagName (`` div '') .near (elem));
driver.switchTo () .newWindow (WindowType.TAB); driver.switchTo () .newWindow (WindowType.WINDOW);
WebDriver newTab = driver.switchTo () .newWindow (WindowType.TAB); newTab.get (`` https: //www.browserstack.com '');
element.getScreenshotAs (OutputType.FILE);
WebElement logo = driver.findElement (By.id (`` logo '')); File screenshot = logo.getScreenshotAs (OutputType.FILE);
How BrowserStack Supports Selenium Testing
Conclusion
Useful Resources for Selenium
Related Guides
Automate This With SUSA
Test Your App Autonomously