Web Element Commands in Selenium

Now that you've mastered browser commands, let's dive into the enchanting realm of Selenium commands designed to identify and interact with WebElements. These commands are your secret tools for handling text boxes, radio buttons, checkboxes, and more – the building blocks of automated test scripts! πŸš€

Text Box Commands - Unleashing the Power of Inputs πŸ’¬βœοΈ

click() - The Initial Encounter πŸ–±

Begin your journey by clicking on the textbox with the mighty click() command.

driver.findElement(By.xpath("//div//input[@id='search']")).click();

sendKeys() - Inscribing the Chronicles πŸ“

Enter the text into a text box by using the sendKeys() command.

driver.findElement(By.xpath("//input[@id='id_q']")).sendKeys("fresher");

clear() - Wiping the Slate Clean 🧼

You can clear the value in a textbox by using the clear() command.

driver.findElement(By.xpath("//input[@id='search']")).clear();

getLocation() - Navigating Coordinates πŸ—Ί

It is used to determine the relative position of an element on a web page. You can either use it to get the location of a particular element or to access the textbox area using the coordinates.

org.openqa.selenium.Point location;
location = driver.findElement(By.xpath("//input[@id='search']")).getLocation();

getSize() - Measuring Dimensions πŸ“πŸ“

If you need to retrieve the height and width (i.e.) the dimensions of an object, you can use the getSize() command.

Dimension dimension = driver.findElement(By.id("GmailAddress")).getSize();
System.out.println("Height of webelement ---> " + dimension.height);
System.out.println("Width of webelement ---> " + dimension.width);

getAttribute() - Unveiling Secrets πŸ•΅οΈβ€β™‚οΈ

You can view the value type in a search text box using the getAttribute() command.

String fieldValue = driver.findElement(By.xpath("XPATHVALUE")).getAttribute("Attributevalue");

getText() - Inner Chronicles πŸ“–

If you’re looking to retrieve the inner text of a particular web element that is not hidden by CSS, use the getText() command.

String elementText = driver.findElement(By.xpath("XPATHVALUE")).getText();

Radio Button/Check Box Commands - Embracing Choices πŸ“»β˜‘οΈ

isSelected() - Verifying Choices βœ”οΈ

Verify whether radio buttons or checkboxes have been selected with isSelected().

boolean isSelected = element.isSelected();

isDisplayed() - In Plain Sight πŸ‘€

You can even verify if the web elements are visible or not using the isDisplayed() command.

boolean isVisible = element.isDisplayed();

isEnabled() - Ready for Action πŸš€

The isEnabled() command can be used to check whether the web elements are enabled or not.

boolean isEnabled = element.isEnabled();

getTagName() - Tagging the Elements 🏷

You can use the getTagName() command to return the tag name of the web elements.

String tagName = element.getTagName();

DropDown Commands - Navigating the Choices πŸŒβ¬‡οΈ

In Selenium Java, dropdowns play a crucial role in web automation, offering various options for user interactions. Three common types of dropdowns are:

  1. Static Dropdown.

  2. Dynamic Dropdown.

  3. Autosuggestive Dropdown.

For a more in-depth exploration of DropDown commands, check out our comprehensive guide in "Handling Dropdowns using Selenium Java". Click here to delve deeper into the specifics and gain additional insights. Happy reading!

Armed with these magical Web Element commands, you're now ready to weave intricate automation scripts with Selenium. Let the automation symphony begin! πŸŽ‰

Β