0

I am trying to get these 6 selectors. I am only able to get 8 it seems. Furthermore, it is dynamic so it keeps changing

//div[@class='sm-CouponLink']//div[@class='sm-CouponLink_Label'] 

The page keeps changing to

//div[@class='sm-Coupon']//div[@class='sm-CouponLink'] 

And other variations of that.

Ideally something like //div[@class*='sm-Coup'] I’ve tried using a wildcard but I’m fairly certain using that xpath does not support this and I am not wanting to use CSS in this case as I am fairly reliant on it. I have also tried:

//div[starts-with(@class, ''sm-Coupo')]

I am on this page here:

https://www.bet365.com.au/#/AS/B1/

enter image description here

Tetora
  • 433
  • 8
  • 25

1 Answers1

1

Try xpath:

//div[starts-with(@class, 'sm-CouponLink_Label')]
//div[contains(@class, 'sm-CouponLink_Label')]

//div[@class='sm-CouponLink']/div[starts-with(@class, 'sm-CouponLink_Label')]

Or XPath if you need wrapper div:

//div[@class='sm-CouponLink'][div[starts-with(@class, 'sm-CouponLink_Label')]]

Or CSS:

div.sm-CouponLink>div[class^='sm-CouponLink_Label']

PS: you xpath //div[starts-with(@class, ''sm-Coupo')] is almost correct, except that it has extra ' quote. Here is the valid one: //div[starts-with(@class, 'sm-Coupo')]

Vitaliy Moskalyuk
  • 2,463
  • 13
  • 15
  • Thanks. The xpath worked and then I think the webpage changed (very dynamic page). Is there a nth-child equivalent for xpath something like .sm-CouponLink_Label:nth-child(1). This page is very dynamic so trying to keep xpath small – Tetora Oct 23 '17 at 11:27
  • n-th element in xpath: https://stackoverflow.com/questions/4007413/xpath-query-to-get-nth-instance-of-an-element – Vitaliy Moskalyuk Oct 23 '17 at 12:32
  • I have something like: //div[starts-with(@class, 'sm-Coupo')][1] . Not really ideal, I may have to find some tutorials on better getting xpaths – Tetora Oct 23 '17 at 15:13