简体   繁体   English

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

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

I'm trying to find an element that repeats itself in the same page. 我正在尝试查找在同一页面中重复的元素。 I tried to use the following XPath's that I was able to find in FirePath, but I didn't have any success running it through my selenium automation tests. 我尝试使用可以在FirePath中找到的以下XPath,但通过自动化测试无法成功运行它。

This are the two XPath: 这是两个XPath:

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

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

And this the information on my page: 这是我页面上的信息:

<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"/>

Screenshot with the two fields and part of the HTML code 屏幕截图,其中包含两个字段和部分HTML代码

Another screenshot with the the HTML code of both input text, showed on the first screenshot 第一个屏幕快照显示了另一个包含两个输入文本的HTML代码的屏幕快照

Use below Xpath 在Xpath下使用

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

It will return you all element with same tag 它将返回具有相同标签的所有元素

Hope it will help you :) 希望它能对您有所帮助:)

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

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

Ok, so I finally had some time to look over it (not really, but made time) and this should work for both elements, per your screenshot. 好的,所以我终于有一些时间来查看它(不是真的,但是花了一些时间),这应该对您的屏幕快照都适用。 You may need to tweak them a lil', hopefully not though. 您可能需要稍微调整一下它们,希望不是。

First Element: 第一个要素:

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

Second Element: 第二要素:

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

I tested them on my end and they work fine. 我最终对它们进行了测试,它们工作正常。 Let me know if it's not working for you somehow. 让我知道它是否对您不起作用。

I would suggest looking into how xpath works and study it, it's actually quite fun once you get the hang of it. 我建议研究一下xpath的工作原理并对其进行研究,一旦掌握了它,它实际上会很有趣。 You are able to find anything on the screen with just some simple parameters. 您只需使用一些简单的参数就可以在屏幕上找到任何内容。

Good luck! 祝好运!

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

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