Angular JS,量角器定位器,获取element的直接子代 [英] Angular JS, Protractor locator, get direct children of element

查看:74
本文介绍了Angular JS,量角器定位器,获取element的直接子代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格,我要从中选择所有行,并且不选择行内的任何元素

I have a grid, from which I want to select all the rows and none of the elements inside the rows

这些行只是div,没有类等,类似这样的内容(为简洁起见,删除了内部内容)

The rows are just divs, no classes etc etc, something like this (inner content removed for brevity)

<div class="grid">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

通常使用量角器定位器,您只需 element(by.css(.grid> div"))

Normally with a protractor locator you could just go element(by.css(".grid > div"))

我遇到的问题是,网格已经是一个量角器元素,我无法控制它,但是我仍然只想选择它的直接子元素.

The issue I have is that grid is already a protractor element and I don't have control over it but I still want to only select its direct children.

var gridElement = element(by.css(".grid"));

所以我需要类似的东西

var rows = gridElement.all(by.css("> div"));

但这不是有效的CSS选择器,因为它缺少左侧.有人知道我该怎么做到吗?

But this is not a valid CSS selector as it's missing the left hand side. Does anyone know how I can achieve this?

不幸的是,使用量角器1.0并更新版本是最后的解决方法

Using protractor 1.0, and updating the version is unfortunately a last-resort

推荐答案

您也可以使用 by.xpath()解决此问题:

You can also solve it with by.xpath():

var rows = gridElement.all(by.xpath("./div"));

这篇关于Angular JS,量角器定位器,获取element的直接子代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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