使用 watin 搜索级联元素

发布于 2024-09-08 03:30:50 字数 148 浏览 1 评论 0原文

请告诉我如何在页面中搜索级联元素。

例如,一个页面中使用了10个锚元素标签。我可以使用 FindBy 方法(即 Element.FindBy())简单地访问一个元素。但是,当我在页面 css 上有一个级联元素(例如“.lineItem .title a”)时该怎么办

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别忘他 2024-09-15 03:30:50

我不确定你所说的“级联元素”是什么意思。您是否正在寻找包含在 class="lineItem" 元素中的 元素,该元素包含在 class="title" 元素中代码>?如果是这样,您至少可以做两件事来查找该元素:

  1. 使用Find.ByExistenceOfRelatedElement(ElementSelector选择器)

    ie.Link(
        Find.ByExistenceOfRelatedElement(link => link.Ancestor(
            Find.ByClass("标题")
            && Find.ByExistenceOfRelatedElement(linksAncestor => linksAncestor.Ancestor(
                Find.ByClass("lineItem"))))));
    
  2. 使用Predicate

    ie.Link(link =>;
    {
        var祖先 = link.Ancestor(Find.ByClass("标题"));
        返回祖先!= null && Ancestor(Find.ByClass("lineItem")) != null;
    });
    

我敢打赌还有另一种方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文