TestStack / TestStack.Seleno

Seleno helps you write automated UI tests in the right way by implementing Page Objects and Page Components and by reading from and writing to web pages using strongly typed view models.
http://teststack.github.com/TestStack.Seleno/
MIT License
180 stars 60 forks source link

How we can use indexes for the return Navigate.To<Page>(By)); #219

Closed sirj77 closed 8 years ago

sirj77 commented 8 years ago

Hi,

I've bumped into some problems that I cannot solve by myself. Is there a way how I can use this expression:

return Find.Elements(By.CssSelector(SomeSelector)).ElementAt(0).Click();

for my interaction method throughout the pages:

        public GeneraPage GoToSomePage(string testLink)
        {
            return Navigate.To<GeneraPage >(By.CssSelector(SelectorCss + testLink+ "']"));
        }

I mean that I need to chose an element by index (because there are two or more elements on the page and I don't have a unique one) and go to an appropriate page. I know that there is no possibility to write like that:

        public GeneralPage GoToSomePage(string testLink)
        {
            return Navigate.To<GeneraPage >(By.CssSelector(SelectorCss + testLink+ "']")).ElementAt(0);
        }

How to rewrite this method properly? Thanks a lot for suggestions!

robdmoore commented 8 years ago

Can you append :nth-child(0) to the css selector?

sirj77 commented 8 years ago

Yes, you are right, it is one way how to do it, thanks. Actually, I managed to find a unique selector for my element.

But anyway, I guess, there is not possibility to rewrite method "GoToSomePage" using .ElementAt(0) in that construction? (return Navigate.To(By.CssSelector(SelectorCss + testLink+ "']")).ElementAt(0);)

robdmoore commented 8 years ago

Yeah - I don't think so. You need to pass a By expression to NAvigate.To that will return a single item.