繁体   English   中英

如何使用XPath查找两个具有相同信息的不同元素

[英]How to find two different elements but with same information using XPath

我正在尝试查找在同一页面中重复的元素。 我尝试使用可以在FirePath中找到的以下XPath,但通过自动化测试无法成功运行它。

这是两个XPath:

//div[@id='selectGenericMult']/child::div/child::input']

(//*[@id='selectGenericMult']/child::div/child::input)[last()]

这是我页面上的信息:

<input class="ui-select-search input-xs ng-pristine ng-valid ng-touched" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="Selecione" ng-disabled="$select.disabled" ng-hide="$select.disabled" ng-click="$select.activate()" ng-model="$select.search" role="combobox" aria-label="Select box" ondrop="return false;" style="width: 1331px;" type="text"/>

屏幕截图,其中包含两个字段和部分HTML代码

第一个屏幕快照显示了另一个包含两个输入文本的HTML代码的屏幕快照

在Xpath下使用

//input[@class='ui-select-search input-xs ng-pristine ng-valid ng-touched' and @role='combobox' and @aria-label='Select box']

它将返回具有相同标签的所有元素

希望它能对您有所帮助:)

要根据您提供的HTML查找元素,可以使用以下唯一的xpath

//input[@class='ui-select-search input-xs ng-pristine ng-valid ng-touched'][@placeholder='Selecione']

好的,所以我终于有一些时间来查看它(不是真的,但是花了一些时间),这应该对您的屏幕快照都适用。 您可能需要稍微调整一下它们,希望不是。

第一个要素:

//div[contains(@class,"ng-scope")]//input

第二要素:

//div[@class="col-md-12"]//input

我最终对它们进行了测试,它们工作正常。 让我知道它是否对您不起作用。

我建议研究一下xpath的工作原理并对其进行研究,一旦掌握了它,它实际上会很有趣。 您只需使用一些简单的参数就可以在屏幕上找到任何内容。

祝好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM