Search for cascading element using watin
Please tell me the way to search a cascading element in a page.
For e开发者_如何学Goxample, there are 10 anchor element tags used in a page. I can simply reach an element using FindBy method i.e. Element.FindBy(). But what to do when i have a cascading element on a page css like ".lineItem .title a"
I am not sure what you mean by saying "cascading element". Are you looking for <a/>
element contained in element with class="lineItem"
which is contained in element with class="title"
? If so, there is at least two things you could do, to find that element:
Use
Find.ByExistenceOfRelatedElement<T>(ElementSelector<T> selector)
ie.Link( Find.ByExistenceOfRelatedElement<Element>(link => link.Ancestor( Find.ByClass("title") && Find.ByExistenceOfRelatedElement<Element>(linksAncestor => linksAncestor.Ancestor( Find.ByClass("lineItem"))))));
Use
Predicate<Link>
ie.Link(link => { var ancestor = link.Ancestor(Find.ByClass("title")); return ancestor != null && ancestor.Ancestor(Find.ByClass("lineItem")) != null; });
I bet there is another way.
精彩评论