This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
8 / 8
Feb 2019

Hi All,

I am trying to select something from a list using class name as ID isn’t available.

The problem I have is that on this page there are 7 options. They all have the same class name! “android.widget.RelativeLayout”. I noticed they have an index that goes in order for 1 to 7.

Currently I have this:

WebElement anotherproblem = driver.findElement(By.className(“android.widget.RelativeLayout”));

While it works it doesn’t click the specific option on the page I want. Is there a way I can tell it to click #1 in the list?

Thanks!

  • created

    Feb '19
  • last reply

    Feb '19
  • 7

    replies

  • 376

    views

  • 3

    users

  • 1

    like

The inspect element gives me an xpath just trying to avoid using that since it’s very long!! Also I believe xpath is the worst one to use.

Can you try like this?

WebElement a= driver.findElement(By.className(“android.widget.RelativeLayout”));
a.findElements(By.tagName(“android.widget.RelativeLayout”)).get(0).click();

and update if any issue

I tried that and I got the error:

Locator Strategy ‘tag name’ is not supported for this session

Trying to find a solution for this as it seems like it will work if I can get it supported!

WebElement element = (WebElement) driver.findElements(By.className(“android.widget.RelativeLayout”)).get(1);
element.click();