【问题标题】:Is there a way to check two different by.css() attributes in the same element() check in protractor?有没有办法在量角器中检查同一个 element() 中的两个不同的 by.css() 属性?
【发布时间】:2016-12-12 07:32:30
【问题描述】:

我正在使用量角器在 HTML 页面上的网格中测试元素。有 2 列和多行。目前我的代码是

browser.element(by.css('div[data-row="1"]')).element(by.css('.widget-toggle-btn')).click();

HTML:

<div data-row="1" data-col="0" ....other stuff here>
    ....(other elements)....
</div>
<div data-row="1" data-col="1" ....other stuff here>
    ....(other elements)....
</div>

但正如您所见,数据行 1 中有 2 列。幸运的是,我想要的列在 'data-col="0"' 中,但我看不到进入切换 btn 的方法那在'data-col =“1”'中。网格是对称的,因此视图中的所有元素都相同,但单击按钮会产生不同的结果。有没有办法让我在 by.css() 定位器中指定两个属性,还是我必须以不同的方式来做?

【问题讨论】:

    标签: javascript css-selectors protractor


    【解决方案1】:

    是的,只需在方括号中添加一个新条件:

    div[data-row=1][data-col=1]
    

    您实际上可以在单个选择器中加入选择器链:

    $('div[data-row=1][data-col=1] .widget-toggle-btn').click();
    

    $()element(by.css()) 的快捷方式。

    【讨论】:

    • 非常感谢!我觉得我会不断寻找问题的来源让你回答:\ lol
    • @amiller956 感谢您提出有趣的问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多