简体   繁体   中英

Finding Certain Element Using XPATH with Not Contains

I am trying to search for a specific object inside a html website that the only difference is a disabled="" . I have attempted to several attempts but none have been successful.

Problem: There is two buttons displayed one that is active and the other one is disabled. My goals is to try to find the xpath only for the one that is enabled. I have attached the HTML for both buttons below.

HTML:

<button _ngcontent-skh-c131="" type="submit" class="mbsp-button btn-submit ng-star-inserted" id="price-submit-21C327109">submit </button>

<button _ngcontent-ylw-c131="" type="submit" class="mbsp-button btn-submit ng-star-inserted" id="price-submit-21C327008" disabled="">submit </button>

Xpath:

//*[(contains(@id, 'price-submit-')and not(contains(@disabled," ")))]

This XPATH returns a finding of two elements when I am expecting only one.

Any help would be appreciated.

The problem is your xpath isn't expressing what you really want. You're asking for elements that do not have a disabled attribute whose value contains a single space. Both do not, so both are selected.

It seems like what you really want is the element that has no disabled attribute whatsoever. Try this:

//*[(contains(@id, 'price-submit-')and not(@disabled))]

or

//button[(contains(@id, 'price-submit-')and not(@disabled))]

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