开发者

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:

  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜