william007
william007

Reputation: 18547

XPath with two conditions

I want to select the div with class "bmBidderButtonText" and with "Low" as inner text, what should I do?

   <div class="bmBidderButtonText"><div class="bmBidderButtonArrow"></div>Low</div>
<div class="bmBidderButtonText"><div class="bmBidderButtonArrow"></div>High</div>

Merely //div[@class="bmBidderButtonText"] will select two divs, but how should I include the "Low" as inner text as condition within the xpath?

Upvotes: 1

Views: 14718

Answers (4)

catch32
catch32

Reputation: 18612

You can use contains() for this reason:

//div[contains(text(), 'Low')]

Additional resources:

Upvotes: 0

Jainish Kapadia
Jainish Kapadia

Reputation: 2611

Try this below xpath

//div[@class='bmBidderButtonText'][text() ='Low']

Explanation:- Use class attribute of <div> tag along with the text method.

Upvotes: 1

har07
har07

Reputation: 89325

You can use . to reference current context element, so implementing additional criteria of "...and with 'Low' as inner text" in XPath would be as simple as adding and .='Low' in the predicate of your initial XPath :

//div[@class="bmBidderButtonText" and .="Low"]

demo

Upvotes: 2

eLRuLL
eLRuLL

Reputation: 18799

use and:

//div[@class="bmBidderButtonText" and contains(., "Low")]

Upvotes: 0

Related Questions