量角器通过div内的标签查找元素 [英] Protractor find an element by tag inside a div

查看:114
本文介绍了量角器通过div内的标签查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML页面中有一个div,其名称总是已知的,在这个div里面有一个href,其详细信息未知。它可能是父母的直接孩子,也可能是更进一步的孙子。看起来像这样:

I've got a div in an HTML Page of which the name is always known and inside this div there is an href, the details of which are not known. It could be the direct child of the parent or it could be a further grandchild. Looks something like this:

<div class="divName">
    ...
        <a href="some url">some text</a>
    ...
</div>

我知道这个div里只有一个链接,所以我想找到一个链接并点击它。

I know that there will only be one link within this div, so I want to find the one link and click it.

我尝试了以下方法,但似乎并未奏效:

I've tried the following but it doesn't seem to be working:

    element(by.classname('divName')).find('a').click();

有什么想法?

Any ideas?

推荐答案

element(by.css('.divName a')).click();

或者简写:

Or the shorter notation:

$('.divName a').click();

这篇关于量角器通过div内的标签查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆