Commands for Element

Go back to tutorial

Commands for Element

We will now be detailing about the various commands to find element with illustrations. Further, these examples showcasing different type of commands to find elements are used in Java.

TYPE 1 – Commands for Element – Commands to Find Element

1. Find Element

This command is used to search for an element on the page. In which case, you will get the first element that matches a locator strategy.

Example –

MobileElement elementOne = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);

MobileElement elementTwo = (MobileElement) driver.findElementByClassName(“SomeClassName”);

HTTP API Specifications

Endpoint – POST /wd/hub/session/:session_id/element

URL Parameters –

  • session_id ID of the session to route the command to

JSON Parameters –

name type description
using string The locator strategy to use
value string The search target

Response – A JSON object for the located element (object)

2. Find Elements

This is primarily used to search for multiple elements. Further it is used to get a list of elements that match the locator selector.

Example –

List<MobileElement> elementsOne = (MobileElement) driver.findElementsByAccessibilityId(“SomeAccessibilityID”);

List<MobileElement> elementsTwo = (MobileElement) driver.findElementsByClassName(“SomeClassName”);

HTTP API Specifications

Endpoint – POST /wd/hub/session/:session_id/elements

URL Parameters –

  • session_id ID of the session to route the command to

JSON Parameters –

name type description
using string The locator strategy to use
value string The search target

Response – A list of JSON objects for the located elements (Array<String>)

 

TYPE 2 Commands for Element – Commands for Actions

1. Click

When you click element at its center point, then the element’s center point is obscured by another element. Such that element click intercepted error is returned.

Example –

MobileElement el = driver.findElementByAccessibilityId(“SomeId”);

el.click();

HTTP API Specifications

Endpoint – POST /wd/hub/session/:session_id/element/:element_id/click

URL Parameters –

  • session_id UUID of the session
  • element_id UUID of the element

JSON Parameters – None

Response – null

2. Send Keys

This command is used to send a sequence of key strokes to an element.

Example –

MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);

element.sendKeys(“Hello world!”);

HTTP API Specifications

Endpoint – POST /wd/hub/session/:session_id/element/:element_id/value

URL Parameters –

  • session_id ID of the session to route the command to
  • element_id ID of the element to send keys to.

JSON Parameters –

name type description
value array<string> The sequence of keys to type. An array must be provided. The server should flatten the array items to a single string to be typed.

Response -null

 

TYPE 3 – Attribute Commands

1. Get Element Text

This is the first type of Attribute command used to return the visible text for the element.

Example –

MobileElement element = (MobileElement) driver.findElementByClassName(“SomeClassName”);

String elText = element.getText();

HTTP API Specifications

Endpoint – GET /wd/hub/session/:session_id/element/:element_id/text

URL Parameters –

  • session_id ID of the session to route the command to
  • element_id ID of the element to get the text from

JSON Parameters – None

Response – null

2. Get Tag Name

This the second type of attribute command used to get an element’s tag name.

Example –

List<MobileElement> element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);

String tagName = element.getTagName();

HTTP API Specifications

Endpoint – GET /wd/hub/session/:session_id/elements/:element_id/name

URL Parameters –

  • session_id ID of the session to route the command to
  • element_id ID of the element to get the name from

JSON Parameters – None

Response -The tag name of the element (string)

Boost your chances for better job opportunities. Practice and Prepare for Mobile Testing (Appium) Exam Now!

Go back to tutorial

Share this post
[social_warfare]
Device Commands
Commands for Interaction

Get industry recognized certification – Contact us

keyboard_arrow_up