0

How to find webElement from within context of a element using webdriver.io

I am trying to find element from within context of existing element. H

Webelement elem1 = driver.findElement(By.id("some id"));
Webelement elem2 = elem1.findElements(By.xpath("some xpath")); //some xpath or css selector within context of elem1's HTML context

How to achieve this using webdriver.io?

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
user2451016
  • 1,857
  • 3
  • 20
  • 44

2 Answers2

1

You can use

elem1 = browser.element('#some id');
elemAll = elem1.elements('some xpath');
0

I am using css selectors for it and you can use it like below example.

If I am looking for an element with classname under specific div,

findElement(By.cssSelector("div[id="my-div"] .elements-class-name")

If I am looking for an element with id under specific div,

findElement(By.cssSelector("div[id="my-div"] #elements-id")

sayhan
  • 1,168
  • 1
  • 16
  • 22