Question Details

No question body available.

Tags

python selector seleniumbase

Answers (1)

Accepted Answer Available
Accepted Answer
August 17, 2025 Score: 0 Rep: 148,927 Quality: High Completeness: 60%

You didn't show real URL so I can't test if there is no other problems.

Your xpath seems incorrect and I think Selenium could even raise error for this (but I'm not sure). If you have it in try/except then for test you should run it without try/except

It should be compared with src, not with input= - something like this

input[contains(@src, "cellstateheadericon.png")]

Next you could make it shorter and skip all these div and other elements because structure can be different and often tbody doesn't exist even if DevTools shows it in HTML.

So to get input I would start with

'//input[contains(@src, "cellstateheadericon.png")]'

and to get th which has this input

'//th[input[contains(@src, "cellstateheadericon.png")]]'

and to get first matching I would test one of this

'//th[1][input[contains(@src, "cellstateheadericon.png")]]'
'//th[input[contains(@src, "cellstateheadericon.png")]][1]'

eventually with ( )

'(//th[1])[input[contains(@src, "cellstateheadericon.png")]]'
'(//th[input[contains(@src, "cellstateheadericon.png")]])[1]'

And if it would find wrong element then I would add more details in xpath.


For test first I would check '//input' to see if it can find any input.


Full code used for tests:

from seleniumbase import SB

---

import seleniumbase print('SeleniumBase:', seleniumbase.version)

---

html = """
Header 1 Header 2 Header 3
"""

#with SB(browser='firefox') as sb: with SB(uc=True) as sb: #sb.open("data:text/html;charset=utf-8," + html) sb.loadhtmlstring(html)

# works #item = sb.wait
forelementpresent('//th[1][input[contains(@src, "icon.png")]]')

# doesn't work - probably it uses XPath 1.0 which doesn't have ends-with() (but it has starts-with()) #item = sb.waitforelementpresent('//th[1][input[ends-with(@src, "icon.png")]]')

# works instead of ends-with() item = sb.wait
forelementpresent('//th[1][input[substring(@src, string-length(@src) - string-length("icon.png") + 1) = "icon.png"]]')

print('text:', item.text)