Closed sirj77 closed 9 years ago
Try .ElementAt(1) rather than [1]
On 31 Jul 2015, at 10:35 pm, sirj77 notifications@github.com wrote:
Hi, I think, it is possible to find an element by index with css selector (in case if I'm having more than one element with the same name of selector expression), but I'm getting an error even without running the tests. Piece of code:
public void Test() { Find.Elements(By.CssSelector(cssSelector))[1]; }
So, on the test page I have 5 elements with the same selector - cssSelector, but I want to find the second one and do some actions with it or make an assertion. And the visual studio says me that there is an error (it underlines in read the "[1])": "Cannot apply indexing to an expression of type System.Collections.Generic.IEnumerable<OpenQA.Selenium.IWebElement".
What I should change to have this piece of code correct, without errors?
— Reply to this email directly or view it on GitHub.
robdmoore, thanks a lot, it works:
public bool Test()
{
get { return Find.Elements(By.CssSelector(cssSelector)).ElementAt(1).Selected; }
}
Hi, I think, it is possible to find an element by index with css selector (in case if I'm having more than one element with the same name of selector expression), but I'm getting an error even without running the tests. Piece of code:
So, on the test page I have 5 elements with the same selector - cssSelector, but I want to find the second one and do some actions with it or make an assertion. And the visual studio says me that there is an error (it underlines in read the "[1])": "Cannot apply indexing to an expression of type System.Collections.Generic.IEnumerable<OpenQA.Selenium.IWebElement".
What I should change to have this piece of code correct, without errors?