【发布时间】:2019-06-30 02:35:44
【问题描述】:
我们正在使用 by.id 来引用一个元素,但 Protractor 仍然抛出此消息“为定位器找到多个元素 By(css 选择器,*[id="txt1"])”,它返回的值是使用 getText() 时的标签。这种行为似乎很奇怪。当我们从 Javascript 中引用该元素时,该引用似乎很好。感谢您帮助解决此问题。
//Code in Protractor, it seems to be referring to a label
var txtEl=element(by.id('txt1'));
//Code in VueJS, where the ID is set to each InputText
//This is the label
<label class="form__label" v-model="form.label" v-show="form.hasOwnProperty('label')">
{{ index }}. {{ form.label }}
</label>
<el-input type="text"
:id="currentField.id"
:placeholder="currentField.isPlaceholderVisible ? currentField.placeholder : ''"
v-model="currentField.value">
</el-input>
//Code in Javascript, works fine, shows the right value
console.log("Value:" + this.$refs.form1["txt1"].value);
【问题讨论】:
-
看起来渲染的页面不知何故得到了重复的 id。尝试对渲染的页面进行截图,看看页面在运行测试时是否正确。
-
这是奇怪的部分,页面看起来是正确的,当我们使用 console.log 打印值时(你可以看到那行),正确的值被打印出来了。
-
添加了 VueJS 代码。 Protractor 正在返回标签的值,甚至不是 InputText。这很奇怪。
-
你确定标签上没有
id="txt1"吗?如果改成element.all(by.id('txt1')),返回多少个元素? -
我已将标签代码添加到我的问题中。如您所见,没有为标签设置 ID,并且值“currentfield:id”仅分配给
的 id。
标签: vue.js protractor