Selenium webdriver 如何定位按钮
以下是两个按钮的源代码:Selenium webdriver 如何定位按钮,selenium-webdriver,protractor,Selenium Webdriver,Protractor,以下是两个按钮的源代码: <div class="picker__footer"> <button class="picker__button--clear" type="button" data-pick="1411929000000" aria-controls="start-date"> :: before "Today" </button> <button class="picker__button--clear" type="
<div class="picker__footer">
<button class="picker__button--clear" type="button" data-pick="1411929000000" aria-controls="start-date"> :: before "Today" </button>
<button class="picker__button--clear" type="button" data-clear="1" aria-controls="start-date"> :: before "Close" </button>
</div>
:“今天”之前
:“关闭”之前
我想在不使用Xpath的情况下单击第二个按钮,实际上我只想使用这些定位器中的任何一个()。在量角器中不使用Xpath是否可以处理这些类型的元素?您应该能够获取部分按钮文本,因此
element(by.partialButtonText('Close')).click();
或者获取所有按钮并使用索引,单击第二个按钮
$$('.picker__button--clear').get(1).click();
您根本不需要使用XPath 如果有重复的按钮,您必须提及按钮的位置 语法:
driver.(byxpath((//*['id=xxxxx'][position()=2]”)。单击();
还有一种方法
element.all(by.css('.picker\u button--clear')).last()
为什么不这样做
element(by.css('button[data-clear]')).click();
谢谢Dollar,但我在问题中已经提到,我根本不想使用xpath。是否有任何方法可以指定
data clear
属性的值。我希望将其用作元素(by.css('button[data clear=1])。单击();
。这样,如果两个WebElement具有相同的属性,那么我可以通过指定相同属性的值使css唯一。