2

I need to detect via xpath an element (image with href) but i know a part of href only

This is the html

<a href="/play.php?video=123456">
<div class="video-splash" data-src="https://myimge-555888.jpg?md5=dfgdfsdgsowVf0QnDcAg&amp;expires=16018841600&amp;origin=103&amp;mid=0df2fd8d-85b1-47da-a371-489a7328ffb4">
<div class="video-time"><i class="fas fa-play"></i> <b>HD</b> 43:25</div>
</div>
</a>

I know the video 123456 (part of href)

video number change periodically

data-src change periodically

I tried these xpaths but in this case do not work

xpath=//a[contains(@href, "123456")]

xpath=//a[ends-with(@href, '123456')]/img

xpath=//a[contains(@href, '123456')]/img

How can i detect the element using a part of href only ?

I need a xpath only that can detect the element please.

Need a generic xpath because some attributes are dynamic video=??? and data-src=??? and <b>???</b> ??? </div>

??? dynamic values that change always, i need to detect it via video number.

I add more html code

<div>

<h2 class="page-h2">
Performer <b>username</b> — Recent Recordings
</h2>
<div class="video-thumb">
<a href="/play.php?video=550420">
<div class="video-splash" data-src="https://v02.frontgross.com/username/2020-04-25,29-59.jpg?md5=BV75Ney9jydwiZgdITkjSg&expires=2705442700&origin=205&mid=5e5c77ca-f750-49ed-9527-725754b972f2">
<div class="video-time"><i class="fas fa-play"></i> <b>HD</b> 59:25</div>
</div>
</a>
<div class="video-info">
<div>
<a href="/?performer=username"><b>username</b></a>
</div>
<div class="video-info-sub"><span class="video-views">22.5K views</span> • 2020-04-25 29:59</div>
</div>
</div>
<div class="video-thumb">
<a href="/play.php?video=529055">
<div class="video-splash" data-src="https://v02.frontgross.com/username/2020-04-25,02-00.jpg?md5=d2GDbtiHuKT-by9A9qcMIA&expires=2705442700&origin=205&mid=5e5c77ca-f750-49ed-9527-725754b972f2">
<div class="video-time"><i class="fas fa-play"></i> <b>HD</b> 45:25</div>
</div>
</a>
<div class="video-info">
<div>
<a href="/?performer=username"><b>username</b></a>
</div>
<div class="video-info-sub"><span class="video-views">20.0K views</span> • 2020-04-25 02:00</div>
</div>
</div>
<div class="video-thumb">
<a href="/play.php?video=529725">
<div class="video-splash" data-src="https://v02.frontgross.com/username/2020-04-24,29-55.jpg?md5=RrwtygDUT_zxTPf4mC2KAw&expires=2705442700&origin=205&mid=5e5c77ca-f750-49ed-9527-725754b972f2">
<div class="video-time"><i class="fas fa-play"></i> <b>HD</b> 2:02:29</div>
</div>
</a>
<div class="video-info">
<div>
<a href="/?performer=username"><b>username</b></a>
</div>
<div class="video-info-sub"><span class="video-views">20.9K views</span> • 2020-04-24 29:55</div>
</div>
</div>
<div class="video-thumb">
<a href="/play.php?video=527092">
<div class="video-splash" data-src="https://v02.frontgross.com/username/2020-04-25,22-00.jpg?md5=unQIgoVWLXy5cBH4sPVWUw&expires=2705442700&origin=205&mid=5e5c77ca-f750-49ed-9527-725754b972f2">
<div class="video-time"><i class="fas fa-play"></i> <b>HD</b> 20:52</div>
</div>
</a>
cicoria
  • 31
  • 6

2 Answers2

0

Try something like this. Be aware of fact that you maybe need to navigate to your link, because I cant see more of your HTML so I do not now is it uniqe.

//*a[starts-with(@herf, 'sometext') and ends-with(@herf, '123456')]
Gaj Julije
  • 1,538
  • 15
  • 32
  • There are error herf must be href. i tried it correct but do not work – cicoria Nov 03 '20 at 22:14
  • I add more html code, your solution do not work. Thanks for suggestion – cicoria Nov 03 '20 at 23:22
  • I can see you have multiple videos, do you know any thing specific related to video element that you want to use. e.g. duration, or maybe that part of link(which is dynamic I assume). .. One more thing i assume that your HTML does not have appropriate formats, it is not ordered by nodes. – Gaj Julije Nov 04 '20 at 08:00
  • I know video=XXXXXX, I want to detect element via video number but i can not find a xpath to detect video using video number. There are a large amount of video, and i have a list of video to open (video=XXXXXX). – cicoria Nov 04 '20 at 16:28
  • If you know the number for video then why don use: ( "//a[@href='/play.php?video=" + videoString+"']") where videoString is String variable – Gaj Julije Nov 04 '20 at 20:09
  • Never of these solution detect the video, seems the videos can not detected by href, i tried all solutions. – cicoria Nov 04 '20 at 21:18
0

This is the solution

xpath=//div/a[@href='/play.php?video=123456']

Need to start xpath with //div/a

Other solutions do not works.

cicoria
  • 31
  • 6