regular expression for an attribute

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

regular expression for an attribute

illusion0reality
I have a table, and want to get the value of name attribute.
THe below code did not work.

I put a dot ( @.=   )   which may work as a regular expression. It may be any attribute- that is my intention.

driver.findElement(By.xpath("//*[@.='myid']" )).getAttribute("name")


<input   name="tbox" id="myid">
Reply | Threaded
Open this post in threaded view
|

Re: regular expression for an attribute

softwaretestingforum
Administrator
I don't know if it is really possible to do so.
You might also like to see -

http://stackoverflow.com/questions/405060/can-i-use-a-regex-in-an-xpath-expression
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: regular expression for an attribute

Illusion0Reality
Thanks for your help Tarun!

In fact, after see this -
selenium.getAtribute(//INPUT[.='something']/@id)  - I thought that . which is before =, works like a regular expression sort.

So if I put . before =, then, based on the attribute's value, another attribute's value (here the id) will be returned.
Reply | Threaded
Open this post in threaded view
|

Re: regular expression for an attribute

softwaretestingforum
Administrator
This is something new for me :)
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: regular expression for an attribute

Illusion0Reality
This worked:

selenium.click("//a[@*='lin']");

Maybe you already used this.
So, old technique.
Reply | Threaded
Open this post in threaded view
|

Re: regular expression for an attribute

softwaretestingforum
Administrator
No I don't think I used it ever, but thanks for sharing.
One random thought, I guess using regular expression this way might take more time to find element. Just an assumption.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: regular expression for an attribute

illusion0reality
Exactly!
Only in some special occasions, this should be very handy.

However, as I used a, I have narrowed down the search.