Equivalent of normalize-space in CSS

625 views
Skip to first unread message

Kaleem Uddin Mohammed Abdul

unread,
Jan 13, 2016, 1:02:24 PM1/13/16
to Selenium Users
Greetings Experts,

I would like to know the corresponding CSS for XPath //*[@id='myslidemenu']//ul//li/a[normalize-space(text())='{0}'].

I need to do cross browser testing and hence planning to use CSS for IE :).

Thanks,
Kaleem.

Kaleem Uddin Mohammed Abdul

unread,
Jan 13, 2016, 1:03:27 PM1/13/16
to Selenium Users
I would like to know the corresponding CSS for XPath //*[@id='myslidemenu']//ul//li/a[normalize-space(text())='{0}'].

I need to do cross browser testing and hence planning to use CSS for IE :).
 I'm using C# (v4.0.30319) with Selenium, IE11 and Win7 combination!

Jim Evans

unread,
Jan 13, 2016, 6:45:24 PM1/13/16
to Selenium Users
You're attempting to find the element by its text content. There is no equivalent CSS selector. Full stop. That is one of the few cases where you must use XPath.
Message has been deleted

PeterJeffreyGale

unread,
Jan 13, 2016, 6:55:33 PM1/13/16
to Selenium Users
Not everythng that you can do in xpath has a direct css eqivalent.

Normalize-space falls into thst category, I believe.

But you could write a wrapper function in programming language that finds all the elements thst match your criteria without that part, and the filters out the (one?) Element that matches your text requirement and returns only that element.

But that would involve more effort on your part and may be as slow to tun as just using xpath.

So you might be as well just using xpath and aim only to run your tests in IE as little as possible.

Kaleem Uddin Mohammed Abdul

unread,
Jan 13, 2016, 9:01:41 PM1/13/16
to Selenium Users
Thanks all for the reply! 
The XPath sometimes work and sometimes doesn't in IE but works perfectly fine in other browsers! I will follow PeterJeffreyGale suggestion for IE alone :)


On Wednesday, January 13, 2016 at 12:02:24 PM UTC-6, Kaleem Uddin Mohammed Abdul wrote:

PeterJeffreyGale

unread,
Jan 14, 2016, 1:58:15 AM1/14/16
to Selenium Users
Different browsers can render the html sent from the server diffrrently as they render the page source sent from the server.

As an xpath expression, yours looks vulnerable to this kind of issue, and the eqivalent CSS may fare no better.

It also looks unnecessarily long, so is likely to be brittle as the application changes.

If you want the stablest solution that is easiest to build and mainting, it would be best to try to understand the reason for the xpath failured snd find a simpler xpath expresssion that works well in all browsers and just stick with that.

Reply all
Reply to author
Forward
0 new messages