Using Multiple Criteria for Finding WebElement in Selenium

I use Selenium to test a website, does it work if I find an element with more than one criteria? eg:

 driverChrome.findElements(By.tagName("input").id("id_Start"));

or

driverChrome.findElements(By.tagName("input").id("id_Start").className("blabla"));
+4
source share
2 answers

No no. You cannot combine / add selectors. In any case, this is not true. However, you can write a selector in such a way as to cover all the scenarios and use it withfindElements()

By byXpath = By.xpath("//input[(@id='id_Start') and (@class = 'blabla')]")
List<WebElement> elements = driver.findElements(byXpath);

This should return you a list of items with tags inputthat have a class name blablaorid id_Start

+4
source

CSS selectors would be ideal in this scenario.

In your example there will be

By.css("input#id_start.blabla")

CSS . , CSS , XPath, Xpath , CSS

+1

Source: https://habr.com/ru/post/1589487/


All Articles