And I'm trying to get this...">

Escape colon in Xpath search

I use Hpricot with selenium. I have this html input element:

<input id="foo:bar"/>

And I'm trying to get this value using this Xpath expression:

source = Hpricot(@selenium.get_html_source)
source.search("//input[@id='foo:bar']")

but he finds nothing because of the colon. I saw that the Xpath expression cannot contain any colon. I tried to avoid this in different ways, but it does not work.

Is there any way to avoid this or avoid this problem? I cannot change the values ​​in html, so foo: bar should be this way with a colon. But I need to somehow find this element.

Any ideas?

thank

+3
source share
3 answers

XPath , id , :

id=foo:bar

id= , .

+2

, , get_element_by_id.

, :

source = Hpricot(@selenium.get_html_source)
source.get_element_by_id("foo:bar")

, .

+2

css- , (, , , ). , Selenium IDE:

css=input[id:contains('foo:bar')]
+1

Source: https://habr.com/ru/post/1752294/


All Articles