值包含时如何通过html属性选择量角器中的元素 [英] How to select element in Protractor by html attribute when value contains
问题描述
在如何选择没有标准唯一 ID 或类的元素方面苦苦挣扎.我将如何使用 Protractor 选择此输入元素?
Struggling with how to select an element that doesn't have a standard unique id or class. How would I select this input element with Protractor?
注意:我不能使用 ComboBoxInput_Default
类,因为这个下拉框用于其他几个页面元素.对于至少 10 多个 DOM 级别,也没有任何易于识别的父元素.
Note: I cannot use the class ComboBoxInput_Default
class, as this drop down box is used on several other page elements. There also isn't any easily identifiable parent element for at least 10+ DOM levels.
<div style="display:inline; white-space: nowrap;" id="ctl00_ctl31_g_b56afa08_7869_450c_8871_f6759a89d9b1_ctl00_WPQ3txtFields_ddPositioList_10_Solution_MultiComboSelection" class="ComboBox_Default">
<input type="text" style="width: 133px; height: 15px;" delimiter=";" class="ComboBoxInput_Default" value="-select-" name="ctl00$ctl31$g_b56afa08_7869_450c_8871_f6759a89d9b1$ctl00$WPQ3txtFields_ddPositioList_10_Solution_MultiComboSelection_Input" id="ctl00_ctl31_g_b56afa08_7869_450c_8871_f6759a89d9b1_ctl00_WPQ3txtFields_ddPositioList_10_Solution_MultiComboSelection_Input" autocomplete="off">
<div>
使每个输入不同的唯一标识标记附加到生成的 id 的末尾,Solution_MultiComboSelection_Input
.
The only identifying markup that makes each of these inputs different is appended to the end of the generated id, Solution_MultiComboSelection_Input
.
如果我必须用 jquery 获取这个元素,我会使用(不推荐)包含 $( "input[name*='Solution_MultiComboSelection_Input']" )
.是否有一些类似的方法可以使用量角器以这种方式定位元素?
If I had to get this element with jquery, I would use the (not preferrable) contains $( "input[name*='Solution_MultiComboSelection_Input']" )
. Is there some comparable way to locate elements in this way with Protractor?
推荐答案
当然,使用contains"或ends-with"CSS 选择器:
Sure, use the "contains" or "ends-with" CSS selector:
element(by.css("input[id*=Solution_MultiComboSelection_Input]"));
element(by.css("input[id$=Solution_MultiComboSelection_Input]"));
这篇关于值包含时如何通过html属性选择量角器中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!