Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

So I use xpath locators and slowly converting to CSS.
I haven't found a way to do an exact match based on text.

For example converting //a[text()='Log Out'].

I know you can do css=a:contains('Log Out') but I want to match exactly to the text. Also I know I can do link=Log Out but looking for a solution with CSS.

share|improve this question

2 Answers 2

up vote 5 down vote accepted
css=a[text='Log Out'] or a[innertext='Log Out']

Can you please try this one out?

Or if that doesn't work and you still don't want to use xpath because it's slow, you can always try: link=Log Out. That's still better then xpath.

EDIT:

So i found a possible solution for you mate. If you are trying to find an exact String you could always use Regular expression like this:

css=div:contains(“^ab$”) 

Just replace div with a and there you go. This will find ONLY AB in whatever text div it looks for. OFC if you have more then one links with text AB (which is a bad thing :P ) then it will find them all..

Try this and see if it helps. :)

share|improve this answer
    
Neither of those work unfortunately. I know I can use link=Log Out but just seeing if there was a solution in CSS. –  Brian O'Neill May 10 '11 at 21:33
    
Sorry to hear that :( Unfortunately I don't think CSS has match exact param. But I might be mistaken. Hope you find an answer soon mate. :) Cheers. –  Hannibal May 10 '11 at 21:36
    
Sorry, I made a mistake... please find edited answer... hope THAT helps. :) –  Hannibal May 10 '11 at 21:38
    
Wow, that worked! I really didn't think it would. Nice job proving me wrong. –  Brian O'Neill May 11 '11 at 0:46
    
Awesome! :) Glad to hear that. And glad i could help. Cheers! :) –  Hannibal May 11 '11 at 4:33

This is a nice place for a few CSS selectors.

http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/

Thought it might be useful for people following this thread.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.