ingwar
ingwar

Reputation: 1

Webdriver search within element

In Telerik it’s possible to search elements within an element that was already found. E.g. I found an ul, that has some elements li. After that I can invoke find() directly from the element.

Is there such possibility using the WebDriver Java?

Upvotes: 0

Views: 296

Answers (2)

e1che
e1che

Reputation: 1251

Actually, you can use
List<WebElement> = driver.findElements(By.cssSelector(".ul li"));

Your list contains all li elements who are in the ul.

Upvotes: 0

Qwerky
Qwerky

Reputation: 18455

In WebDriver the usual way of finding an element on the page is;

WebElement element = driver.findElement(By.xpath("xpath query here"));

The findElement method is provided by SearchContext inferface, which WebElement also extends. This means you can call findElement on any element found by a previous search;

WebElement child = element.findElement(By.xpath("another xpath query"));

Upvotes: 3

Related Questions