1

In c# i always use

 `IList<IWebElement> SearchResult1 = Setup.driver.FindElements(By.CssSelector("div.comma.line"));` 

and i access the SearchResult1 by SearchResult1[0] or SearchResult1 []. It allow me to click on the SearchResult1[0] too.

But how am i going to do this in Java. I have this list and cant access the list by its index number.

List<WebElement> matches = TopLayer.findElements(By.tagName("li"));
matches[0]

Im getting an error.

asked Mar 17, 2017 at 2:59

2 Answers 2

2

For list iterator use below loop

for ( WebElement we: matches ) { 
 //Do something 
}

or you can: matches.get(0); or matches.get(1); and so on

zishan paya
2111 gold badge2 silver badges12 bronze badges
answered Mar 17, 2017 at 3:36
0

Array can be access by its index like matches[0], matches[1] while List is a ordered collection in Java. To access or add elements in list by using matches.get(index) or matches.add(value) methods.

Refer how to use list in Java

answered Mar 17, 2017 at 4:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.