doingmybest
doingmybest

Reputation: 314

select element based on class and attribute value

I'm trying to use Xpath in order to select an HTML tag based on its value

Here is my html code:

 <span class="yellowbird">Continue</span>
 <span class="yellowbird">Stop</span>

I can select the span elements with a specific class value using

//span[contains(@class, 'yellowbird')]

However I'm struggling to select only the element which contains the value "Continue"

Upvotes: 0

Views: 87

Answers (2)

doingmybest
doingmybest

Reputation: 314

Here is the syntax I used to make this work using request.xpath and scrapy

//span[contains(@class, 'yellowbird')][1]//text()='Continue'

Upvotes: 0

ck1
ck1

Reputation: 5443

This XPath expression will select any span element whose class attribute equals yellowbird and text equals Continue:

//span[@class='yellowbird' and text()='Continue']

Upvotes: 2

Related Questions