tags:

views:

36

answers:

1

Please tell me the way to search a cascading element in a page.

For example, 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"

+1  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:

  1. 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"))))));
    
  2. 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.

prostynick