1

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="/mysite.com?id=123456"><img src="//user/banners/16/08/1614708.gif" alt="AAA" data-tip="BBB" currentitem="false" class="" width="468" height="60"></a>

I know the id 123456 (part of href)

I tried this xpath that recognize element with a part of href but working in text link only

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

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

I need xpath only please.

cicoria
  • 31
  • 6
  • Does this answer your question? [Find xpath in html element using a part of href only katalon recorder, kantu, selenium ide, ui vision](https://stackoverflow.com/questions/64655194/find-xpath-in-html-element-using-a-part-of-href-only-katalon-recorder-kantu-se) – chivracq Aug 06 '22 at 12:57

2 Answers2

0

You can use regular expresions. Something like

driver.find_element_by_xpath("//input[starts-with (@name,'Tut')]")

or as you described

driver.find_element_by_xpath("//input[contains(@name,'sel')]").

Be awere of one thing, do not use double quotes, for the string you are searching as atribute value. Use a single quote like I previously described.

Gaj Julije
  • 1,538
  • 15
  • 32
0

You need get /img in //a where href attribute contains() or ends-with() your id This is XPATH that you need. At least i would use this XPATH in this situation

//a[ends-with(@href, 'your-id-here')]/img