简体   繁体   中英

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.

This are the two 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

Another screenshot with the the HTML code of both input text, showed on the first screenshot

Use below 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. You are able to find anything on the screen with just some simple parameters.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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