Skip to main content

Desktop Driver Element

Desktop Driver Element

DesktopElement represents a UI element on the screen. DesktopElement can be found by searching using a DesktopDriver instance. Getting DesktopElement by searching  under another DesktopElement is not supported yet.

DesktopDriver API provides built-in methods to find the DesktopElement which are based on different properties like ID, Name, Text, etc.

Click

Clicks on this element.

driver.findElement(DesktopSearch.query(DesktopSearch.UIQuery.builder().className("Button")).click();

Is Element enabled

This method is used to check if the referenced Element is enabled or disabled on a screen. Returns a boolean value, True if the referenced element is enabled in the current browsing context else returns false.

//returns true if element is enabled else returns false
boolean value = driver.findElement(DesktopSearch.query(DesktopSearch.UIQuery.builder().className("Edit")).isEnabled();

Is Element Selected

This method determines if the referenced Element is Selected or not. This method is widely used on Check boxes, radio buttons, input elements, and option elements.

Returns a boolean value, True if referenced element is selected in the current browsing context else returns false.

//returns true if element is checked else returns false
boolean value = driver.findElement(DesktopSearch.query(DesktopSearch.UIQuery.builder().className("Checkbox")).isSelected();

Get Element Tag Name (Control Type)

It is used to fetch the Control Type value of the referenced Element. "Tag name" in context of Desktop Driver means the ControlType attribute value.

//returns ControlType of the element
String value = driver.findElement(DesktopSearch.query(DesktopSearch.UIQuery.builder().name("Text Editor")).getTagName();

Get Element Rect

It is used to fetch the dimensions and coordinates of the referenced element.

The fetched data body contain the following details:

  • X-axis position from the top-lef corner of the element
  • y-axis position from the top-lef corner of the element
  • Height of the element
  • Width of the element


// Returns height, width, x and y coordinates referenced element
Rectangle res =	driver.findElement(DesktopSearch.query(DesktopSearch.UIQuery.builder().name("Text Editor")).getRect();

// Rectangle class provides getX,getY, getWidth, getHeight methods
System.out.println(res.getX());

Get Element Text

Retrieves the rendered text of the specified element.

// Retrieves the text of the element
String text = driver.findElement(DesktopSearch.query(DesktopSearch.UIQuery.builder().className("Edit")).getText();