Selenium WebElement Commands
Related Product On This Page What is a Selenium WebElement?June 05, 2026 · 9 min read · Tool Comparison
A WebElementin Selenium represents an HTML element on a web page, allowing interaction (click, direct keys, retrieve schoolbook) through method likeclick(), sendKeys (), and getText(). WebElements provide methods to interact with those component, retrieve information, and verify element properties. When you use Selenium to automate a web browser, you & # 8217; ll want to name elements on the page and interact with them. Selenium WebElement objective are how you negociate those interactions. These elements are found using different locators The WebElement interface in Selenium enable interaction with both visible and obscure elements on a web page. WebElement command return either null/void or the ingredient found. Syntax of Selenium WebElement Every method either returns a value or returns null/void (no value). The WebElement class in Selenium WebDriver works the same way. Here ’ s an example of a WebElement in Selenium command: This command returns either the element being research for or returns null/void. All activeness on any WebElement will perpetually populate against any factor, regardless of whether an action is valid on the element or not. There are different types of WebElement Commands in Selenium to interact with the web elements. These method use the Web elements to interact with both visible and obscure ingredient on a web page. Methods in Selenium either return a value or nothing (null/void). Here is the elaborated list of WebElements Commands in Selenium: allows the user to type substance automatically into an editable field while executing trial. These fields are web elements that can be identify using like element id, gens, class name, etc. Syntax: This method uses CharSequence as a argument. It returns zero. It act with text entry elements such asINPUT and TEXTAREA. Example: Read More: The in Selenium verifies if a especial constituent is present and displayed. If the element is displayed, then the value retrovert is true. If not, then the value returned is a. Syntax: The code below verifies if an element with the id attribute value next is displayed. Example: Note: If an element is present on a web page but its property is set to hidden, the Selenium WebDriver isDisplayed method will render NoSuchElementFound. This is because still though the element is present in the DOM, it is not visible to users. This command only works on input element such as tuner buttons, checkboxes, select options, and menu items. It is used to determine if an element is selected. If the specified element is selected, the value returned is true. If not, the value returned is false. Syntax: Example: This bid is handy when interact with forms (or constituent within a form) on a web page. It doesn ’ t require a parameter and return cypher. As evident from its name, the command submit relevant info (as require) on a site. If the action triggered by this dictation alter the current web page, the method will wait until the new page loads. Syntax: SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. Example: Also Read: This WebElement in Selenium command verifies if an ingredient is enabled on the web page. If the element is enabled, it returns a true value. If not, it returns a false value. Syntax: The codification below verifies if an element with the id attribute value adjacent is enabled. Example: This command retrieves the location of a specified constituent on a web page. It does not require a parameter and returns the Point object as its result. The X and Y coordinates of the element can be deduce from the Point object returned. Syntax: Example: When using this WebElement in Selenium command, its value will be cleared if the element in question is a text entry. It doesn ’ t require a parameter and returns nothing. Syntax: The open () method does not affect early web element. The text entry ingredient here areINPUT and TEXTAREA. Example: This command retrieve the schoolbook within a specific web element. This includes the interior text as well as the sub-elements sans whitespace. It doesn ’ t require a argument and returns a string value. This method is often habituate to control labels, messages, error, and other elements (regard text) expose to website visitors. Syntax: Example: This method retrieve the tag name of the specified ingredient. It does not require a parameter and returns a thread value as its solvent. Syntax: This bidding perform not return the value of the gens dimension. It returns the tag. For example, if the code is& lt; input name= & # 8221; foo & # 8221; / & gt;, then this command will return the tag, i.e.“input”. Example: This dictation retrieves the CSS property value of a specified element. It does not require a argument and returns a string value as its result. Syntax: Example: This dictation find the attribute value of a specified element. It habituate String as the parameter and returns a draw value as its result. Syntax: Example: The click () command lets the tester replicate the click action on a button, link, radiocommunication push or checkbox. In Webdriver, the click occurs after the ingredient is found. In, the recorder identifies the element, the dictation itself performs the click. Syntax: Example: This dictation retrieves the stature and width of a specific rendered element. It does not ask a parameter and return the Dimension object as its result. Syntax: Example: You should run Selenium Tests on a real device cloud like for below intellect: WebElement in Selenium commands are crucial for tester seeking to automatise user activity on a website to verify its performance. The bid remark supra will go a long way in the thorough of website. Selenium tests return the best resultant when run on a. # 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
Selenium WebElement Commands
What is a Selenium WebElement?
& lt; start tag & gt; message & lt; /end tag & gt;
WebElement element = driver.findElement (By.id (“ UserName “));
List of Selenium WebElement Commands
Selenium WebElement Methods
1. sendKeys () command
element.sendKeys (“ text ”);
// Create WebElement WebElement elesendKeys = driver.findElement (By.id (`` TextBox '')); // Perform sendKeys operation elesendKeys.sendKeys (`` Cheese ''); // OR // Send value to particular WebElement e.g: Textbox. driver.findElement (By.id (`` TextBox '')) .sendKeys (`` Cheese '');
2. isDisplayed () command
element.isDisplayed ();
boolean eleSelected= driver.findElement (By.xpath (`` xpath '')) .isDisplayed ();
WebElement ingredient = driver.findElement (By.id (`` UserName '')); boolean status = element.isDisplayed (); //Or can be written as boolean status = driver.findElement (By.id (`` UserName '')) .isDisplayed ();
3. isSelected () command
element.isSelected ();
WebElement ingredient = driver.findElement (By.id (`` Sex-Male '')); boolean status = element.isSelected (); //Or can be written as boolean staus = driver.findElement (By.id (`` Sex-Male '')) .isSelected ();
4. submit () command
element.submit ();
WebElement element = driver.findElement (By.id (`` SubmitButton '')); element.submit (); //Or can be pen as driver.findElement (By.id (`` SubmitButton '')) .submit (); WebElement element = driver.findElement (By.id (`` SubmitButton '')); element.submit (); //Or can be written as driver.findElement (By.id (`` SubmitButton '')) .submit ();
5. isEnabled () command
element.isEnabled ();
boolean eleEnabled= driver.findElement (By.xpath (`` xpath '')) .isEnabled ();
// Create WebElement WebElement eleEnabled = driver.findElement (By.id (`` TextBox '')); // Perform isEnabled operation eleEnabled.isEnabled (); // OR // Verify WebElement is Enabled or Not? e.g: Radio / Checkbox. driver.findElement (By.id (`` Text '')) .isEnabled ();
6. getLocation () dictation
element.getLocation ();
WebElement element = driver.findElement (By.id (`` SubmitButton '')); Point point = element.getLocation (); System.out.println (`` X cordinate: `` + point.x + `` Y cordinate: `` + point.y);
7. clear () bidding
element.clear ();
// Create WebElement WebElement eleClear = driver.findElement (By.id (`` TextBox '')); // Perform open operation eleClear.clear (); // OR // Clear particular WebElement e.g: Textbox. driver.findElement (By.id (`` TextBox '')) .clear ();
8. getText () bidding
element.getText ();
// Create WebElement WebElement elegetText = driver.findElement (By.id (`` TextBox '')); // Perform getText operation elegetText.getText (); // OR // Get text of Particular WebElement & amp; amp; Store into String driver.findElement (By.id (`` TextBox '')) .getText ();
9. getTagName () commandelement.getTagName ();
// Create WebElement WebElement elegetTagName = driver.findElement (By.id (`` TextBox '')); // Perform getTagName operation elegetTagName.getTagName (); // OR // Able to get TagName of Particular WebElement & amp; amp; Store into String driver.findElement (By.id (`` TextBox '')) .getTagName (); // Create WebElement WebElement elegetTagName = driver.findElement (By.id (`` TextBox '')); // Perform getTagName operation elegetTagName.getTagName (); // OR // Able to get TagName of Particular WebElement & amp; amp; Store into String driver.findElement (By.id (`` TextBox '')) .getTagName ();
10. getCssValue () commandelement.getCssValue ();
//Locating textBox component using CSS Selector WebElement textBox = driver.findElement (By.cssSelector (`` div # textBox ``)); //Performing sendKeys operation on the element textBox.sendKeys (`` stqatools '');
11. getAttribute () bidelement.getAttribute ();
WebElement element = driver.findElement (By.id (`` SubmitButton '')); String attValue = element.getAttribute (`` id ''); //This will render `` SubmitButton ''
12. chink () command
element.click ();
// Create WebElement WebElement eleclick = driver.findElement (By.id (`` TextBox '')); // Perform click operation eleclick.click (); // OR // Click on any WebElement e.g: Button. driver.findElement (By.id (`` Button_Id '')) .click (); // Create WebElement WebElement eleclick = driver.findElement (By.id (`` TextBox '')); // Perform click operation eleclick.click (); // OR // Click on any WebElement e.g: Button. driver.findElement (By.id (`` Button_Id '')) .click ();
13. getSize () command
element.getSize ();
WebElement element = driver.findElement (By.id (`` SubmitButton '')); Dimension dimension = element.getSize (); System.out.println (“ Height: ” + dimensions.height + ” Width: `` + dimensions.width);
Why use BrowserStack Automate to run Selenium Tests?
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously