<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Selenium Testing? Do Cross Browser Testing with Sauce Labs &#187; css selectors</title>
	<atom:link href="http://saucelabs.com/blog/index.php/tag/css-selectors/feed/" rel="self" type="application/rss+xml" />
	<link>http://saucelabs.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 31 Jan 2012 20:58:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Why CSS Locators are the way to go vs XPath</title>
		<link>http://saucelabs.com/blog/index.php/2011/05/why-css-locators-are-the-way-to-go-vs-xpath/</link>
		<comments>http://saucelabs.com/blog/index.php/2011/05/why-css-locators-are-the-way-to-go-vs-xpath/#comments</comments>
		<pubDate>Tue, 17 May 2011 14:15:55 +0000</pubDate>
		<dc:creator>Ashley Wilson</dc:creator>
				<category><![CDATA[Meetups]]></category>
		<category><![CDATA[Selenium Knowledge]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css selectors]]></category>
		<category><![CDATA[Locators]]></category>
		<category><![CDATA[selenium tips]]></category>
		<category><![CDATA[sfse]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://saucelabs.com/blog/?p=3988</guid>
		<description><![CDATA[Last week, our own Santiago Suarez Ordoñez gave a presentation to the San Francisco Selenium Meetup group that convinced us all to say no (for the most part) to XPath and yes to CSS Locators in our Selenium tests. In his role as official Sauce Ninja and as a prolific poster in the Selenium forums, [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, our own Santiago Suarez Ordoñez gave a presentation to the <a href="http://meetup.com/seleniumsanfrancisco">San Francisco Selenium Meetup group</a> that convinced us all to say <strong>no</strong> (for the most part) to XPath and <strong>yes</strong> to CSS Locators in our Selenium tests.</p>
<p>In his role as official Sauce Ninja and as a prolific poster in the Selenium forums, Santi has helped more users solve locator issues than possibly anyone else in the world. He&#8217;s previously written a number of <a href="http://saucelabs.com/blog/index.php/tag/css-selectors/">blog posts</a> on ways to improve locator performance. As Sauce CEO John Dunham puts it, &#8220;If there was a foursquare mayorship for locators, Santi would have it for a lifetime.&#8221;</p>
<p>Drawing from this experience, he gave us these four reasons for using CSS Locators:</p>
<p>1. They&#8217;re faster<br />
2. They&#8217;re more readable<br />
3. CSS is jQuery&#8217;s locating strategy<br />
4. No one else uses XPATH anyways!</p>
<p>I can&#8217;t speak for everyone, but Santi sure sold me on point number one when he showed off the <a href="https://gist.github.com/963821">performance metric script</a> he wrote a script that tested the speed of XPath vs the speed of CSS Locators. There wasn&#8217;t much of a difference in Firefox, Safari, or Chrome, but with IE, the results were undeniable. Take a look:<br />
<a rel="attachment wp-att-3990" href="http://saucelabs.com/blog/index.php/2011/05/why-css-locators-are-the-way-to-go-vs-xpath/screen-shot-2011-05-16-at-2-49-24-pm/"><img class="aligncenter size-large wp-image-3990" title="Screen shot 2011-05-16 at 2.49.24 PM" src="http://saucelabs.com/blog/wp-content/uploads/2011/05/Screen-shot-2011-05-16-at-2.49.24-PM-600x205.png" alt="" width="450" height="153" /></a></p>
<p>To underscore this even further, he also recorded a video in <a href="http://saucelabs.com/ondemand">Sauce OnDemand</a> that uses one heck of a cute kitten to illustrate just how <em>slow</em> XPath can be. The cat&#8217;s paw movements represent the test clicking through the different locators. The first batch of clicks uses CSS Locators and completes in under 30 seconds. The second batch, the XPath one, continues on for another <strong>eight minutes</strong>. Eight minutes!</p>
<p><object id="player_api" width="500" height="349" type="application/x-shockwave-flash" data="/flowplayer/flowplayer-3.2.5.swf?0.32766646798700094" name="player_api"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="quality" value="high" /><param name="cachebusting" value="true" /><param name="bgcolor" value="#000000" /><param name="flashvars" value="config={&quot;clip&quot;:{&quot;url&quot;:&quot;/jobs/8eca38f844ffbc91336eddefad84177e/video.flv&quot;,&quot;provider&quot;:&quot;streamer&quot;,&quot;autoPlay&quot;:false,&quot;autoBuffering&quot;:true},&quot;plugins&quot;:{&quot;streamer&quot;:{&quot;url&quot;:&quot;/flowplayer/flowplayer.pseudostreaming-3.2.5.swf&quot;},&quot;controls&quot;:{&quot;mute&quot;:false,&quot;volume&quot;:false,&quot;backgroundColor&quot;:&quot;rgba(0, 0, 0, 0.7)&quot;}},&quot;playerId&quot;:&quot;player&quot;,&quot;playlist&quot;:[{&quot;url&quot;:&quot;/jobs/8eca38f844ffbc91336eddefad84177e/video.flv&quot;,&quot;provider&quot;:&quot;streamer&quot;,&quot;autoPlay&quot;:false,&quot;autoBuffering&quot;:true}]}" /></object></p>
<p>During the rest of the presentation, Santi dives into writing both basic and more advanced CSS Locators. He also spends some time talking about when you <strong>shouldn&#8217;t</strong> use CSS Locators (yes, there are a few cases where it is not the right tool for the job). To see the talk in its entirety, check out the recording below. And if you&#8217;re thinking of switching over from XPath, but unsure of how to go about it, check out the nifty tool Santi wrote called <a href="https://github.com/santiycr/cssify">cssify</a>. It does the handy work of translating your XPaths to CSS automatically.</p>
<p><strong>Helpful links</strong><br />
View Santi&#8217;s <a href="http://dl.dropbox.com/u/129692/locators.html#0">Presentation Slides</a><br />
Follow him on <a href="http://twitter.com/santiycr">Twitter</a><br />
Follow Sauce on <a href="http://twitter.com/saucelabs">Twitter</a><br />
Join the <a href="http://meetup.com/seleniumsanfrancisco">San Francisco Selenium Meetup group</a>!</p>
<p><object width="560" height="349"><param name="movie" value="http://www.youtube.com/v/6vPu3TO6XZ4?fs=1&amp;hl=en_US" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="560" height="349" src="http://www.youtube.com/v/6vPu3TO6XZ4?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Enjoy!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsaucelabs.com%2Fblog%2Findex.php%2F2011%2F05%2Fwhy-css-locators-are-the-way-to-go-vs-xpath%2F&amp;title=Why%20CSS%20Locators%20are%20the%20way%20to%20go%20vs%20XPath" id="wpa2a_2"><img src="http://saucelabs.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://saucelabs.com/blog/index.php/2011/05/why-css-locators-are-the-way-to-go-vs-xpath/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Why jQuery in Selenium CSS Locators Is The Way To Go</title>
		<link>http://saucelabs.com/blog/index.php/2011/01/why-jquery-in-selenium-css-locators-is-the-way-to-go/</link>
		<comments>http://saucelabs.com/blog/index.php/2011/01/why-jquery-in-selenium-css-locators-is-the-way-to-go/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 21:38:10 +0000</pubDate>
		<dc:creator>Santiago Suarez Ordoñez</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Selenium Knowledge]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[CCS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[css selectors]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Locators]]></category>
		<category><![CDATA[Sauce Labs]]></category>
		<category><![CDATA[sauce ondemand]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://saucelabs.com/blog/?p=2962</guid>
		<description><![CDATA[You may not have heard about this, but a while ago, Jason Huggins moved Selenium 1&#8242;s CSS locator engine from CSSQuery to Sizzle, jQuery&#8217;s CSS selector library. While this may not sound like a big deal to most users, it actually is, and in this blog post, I&#8217;ll explain why and how to start using [...]]]></description>
			<content:encoded><![CDATA[<p>You may not have heard about this, but a while ago, Jason Huggins moved Selenium 1&#8242;s CSS locator engine from <a href="http://dean.edwards.name/my/cssQuery/">CSSQuery</a> to <a href="http://sizzlejs.com/">Sizzle</a>, jQuery&#8217;s CSS selector library.</p>
<p>While this may not sound like a big deal to most users, it actually is, and in this blog post, I&#8217;ll explain why and how to start using all the cool features that come with this change.</p>
<div style="border:1px solid lightgray; padding: 10px; font-size:0.9em"><span style="text-decoration: underline;">Update</span>: For those of you using or willing to use Selenium 2/Webdriver, you may want to re-consider the special Sizzle pseudoclases like <strong>:contains</strong> or <strong>:nth </strong>that I&#8217;m talking about in this blog post. For technical reasons, injecting Sizzle in browsers driven by Selenium 2 is not as cheap as with Selenium 1, so the Devs have decided to rely on the browsers&#8217; implementation of CSS (standard CSS only) and fallback to Sizzle when needed (in case of old browsers which don&#8217;t provide native css selecting for JavaScript). In Selenium 2 land, my advice, sadly, is to stick to the standard and avoid most of these shortcuts :,(</div>
<p><img class="alignright size-full wp-image-3053" title="sizzle" src="http://saucelabs.com/blog/wp-content/uploads/2011/01/sizzle.png" alt="" width="287" height="147" /></p>
<h3>Why is Sizzle awesome?</h3>
<p>Well, Sizzle is <a href="http://jquery.com/">jQuery</a>&#8216;s selector engine, and that means A LOT. For those of you who don&#8217;t know, jQuery is the javascript library used by almost <a href="http://w3techs.com/technologies/history_overview/javascript_library/all">30 percent of all the websites</a>. (As in, &#8220;30 percent of the whole effing Internet!&#8221;).</p>
<p>Because of that, Sizzle gets an insane amount of usage, and therefore, testing. Sizzle&#8217;s code is used by an average of 1 site for every 3 you visit. Its <a href="https://github.com/jeresig/sizzle">codebase</a> has over a thousand followers on github and more than 80 forks as of today. That&#8217;s a lot of eyes to catch bugs and improve performance.</p>
<p>But it&#8217;s not just a more robust and faster implementation of CSS that works on every browser. It has <a href="http://ejohn.org/blog/selectors-that-people-actually-use/">removed useless CSS selectors</a> and added extra goodies that turn out to be pretty useful for people writing tests.</p>
<h3>Sizzle&#8217;s extra features you can use right now</h3>
<p>As it says in <a href="https://github.com/jeresig/sizzle/wiki">its docs</a>, Sizzle not only implements virtually all <a href="http://www.w3.org/TR/css3-selectors/">CSS 3 Selectors</a>, but also extends them a little bit and adds its own, including some that are actually pretty useful for writing Selenium tests:</p>
<p><strong>:not</strong></p>
<p>The <code>:not</code> selector will help you filter out elements that are similar, but not exactly what you&#8217;re looking for. Let&#8217;s imagine the following situation:</p>
<pre class="brush:html">&lt;a href="#meh" class="confirmation_link hidden"&gt;Confirm&lt;/a&gt;
... lots of html ...
&lt;a href="#bleh" class="confirmation_link"&gt;Confirm&lt;/a&gt;</pre>
<p>As you can see here, there are two links in the page you&#8217;re trying to test. Since they both have the same text, <code>link=Confirm</code> won&#8217;t work because they&#8217;re the same class and there is no id you could use to be more specific. In this kind of situation, the <code>:not</code> selector is our perfect weapon. It&#8217;s just as simple as writing the following locator:</p>
<pre class="brush:python">selenium.click("css=a.confirmation_link:not(.hidden)")</pre>
<p>Thanks to Sizzle, complex filters can go inside <code>:not</code>. Here are some other examples:</p>
<pre class="brush:python">selenium.click("css=.confirmation_link:not(div)")</pre>
<pre class="brush:python">selenium.click("css=.submit_button:not(#clear_button)")</pre>
<pre class="brush:python">selenium.click("css=input[type=button]:not(p#not_this_input &gt; input)")</pre>
<p><strong>:contains</strong></p>
<p>Even though <code>:contains</code> was already present in cssQuery and the old Selenium, I thought it was worth mentioning. It can be used to filter elements depending on their inner text, so you can do something like:</p>
<pre class="brush:python">selenium.click("css=div#myID &gt; a:contains(Confirm Transaction)")</pre>
<p><strong>:eq/:nth</strong></p>
<p>This selector finds all the occurrences and then just filters the nth in the list. If are using the confusing :nth-of-type or :nth-child filters, this may be a great replacement.</p>
<pre class="brush:python">selenium.click("css=table a:contains(Change password):nth(5)")</pre>
<p><strong>:header</strong></p>
<p>This selector will find you any header element. That is, h1, h2, h3, h4, h5 or h6. Pretty cool, huh? This way you can forget about which type of header your devs choose to use in the page. All you care to know is that it&#8217;s going to be a header.</p>
<p>Asserting a header that contains a specific text is the perfect situation for this:</p>
<pre class="brush:python">assert selenium.is_element_present(":header:contains(Users Admin)")</pre>
<p><strong>Form helpers</strong></p>
<p>Additionally, Sizzle includes some form element shortcuts to save you from having to find out whether the element is a textarea element or an input. Even better, it saves you from writing ugly locators like <code>input[type=checkbox]</code>.</p>
<ul>
<li><code>:input</code>: Finds all input elements (includes textareas, selects, and buttons).</li>
<li><code>:text</code>, <code>:checkbox</code>, <code>:file</code>, <code>:password</code>, <code>:submit</code>, <code>:image</code>, <code>:reset</code>, <code>:button</code>: Finds the input element with the specified input type (:button also finds button elements).</li>
</ul>
<p>I think those are all important and you can check out the <a href="https://github.com/jeresig/sizzle/wiki  ">Sizzle&#8217;s wiki</a> for more info. We also released a <a href="http://saucelabs.com/downloads/documentation/css-selector-quickreference.pdf">CSS selectors quick reference</a> if you&#8217;d like to have a cheat-sheet printed and close to your desk while you&#8217;re writing your tests ;)</p>
<p>Hope everyone is now writing jQuery Selenium selectors and found this post useful for saving some time and headaches. Of course, all of this is already available in our <a href="http://saucelabs.com/ondemand">browsers in the cloud service</a>, Sauce OnDemand, so go <a href="https://saucelabs.com/pricing">try it out for free</a>!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsaucelabs.com%2Fblog%2Findex.php%2F2011%2F01%2Fwhy-jquery-in-selenium-css-locators-is-the-way-to-go%2F&amp;title=Why%20jQuery%20in%20Selenium%20CSS%20Locators%20Is%20The%20Way%20To%20Go" id="wpa2a_4"><img src="http://saucelabs.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://saucelabs.com/blog/index.php/2011/01/why-jquery-in-selenium-css-locators-is-the-way-to-go/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Selenium Tips: Finding elements by their inner text using :contains, a CSS pseudo-class</title>
		<link>http://saucelabs.com/blog/index.php/2010/03/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class/</link>
		<comments>http://saucelabs.com/blog/index.php/2010/03/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 17:36:33 +0000</pubDate>
		<dc:creator>Santiago Suarez Ordoñez</dc:creator>
				<category><![CDATA[Selenium Knowledge]]></category>
		<category><![CDATA[css selectors]]></category>
		<category><![CDATA[selenium tips]]></category>

		<guid isPermaLink="false">http://saucelabs.com/blog/?p=801</guid>
		<description><![CDATA[As we already mentioned in our previous posts CSS Selectors in Selenium Demystified and Start improving your locators, CSS as a location strategy generally far outperforms XPATH. That&#8217;s why for this Tip of the Week, we are presenting our users one more CSS pseudo-class to keep moving their test suites to this faster and cleaner [...]]]></description>
			<content:encoded><![CDATA[<p>As we already mentioned in our previous posts <a href="http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/">CSS Selectors in Selenium Demystified</a> and <a href="http://saucelabs.com/blog/index.php/2009/10/selenium-tip-of-the-week-start-improving-your-locators/">Start improving your locators</a>, CSS as a location strategy generally far outperforms XPATH.</p>
<p>That&#8217;s why for this Tip of the Week, we are presenting our users one more CSS pseudo-class to keep moving their test suites to this faster and cleaner location strategy.</p>
<p>Let&#8217;s imagine you have an element like the following:</p>
<pre class="brush:html">&lt;div&gt;Click here&lt;/div&gt;</pre>
<p>The easiest way to locate it is using it&#8217;s &#8220;Click here&#8221; inner text and in XPATH you would do it using XPATH&#8217;s text() function:</p>
<pre class="brush:plain">//div[text() = "Click here"]</pre>
<p>or even better (because the previous version can sometimes fail depending on the browser):</p>
<pre class="brush:plain">//div[contains(text(), "Click here")]</pre>
<p>Now, if you want to move your locators to CSS in situations like this one, all you have to do is use the <strong>:contains()</strong> pseudo-class, with which your tests would end up using the following locator:</p>
<pre class="brush:plain">css=div:contains("Click here")</pre>
<p>Did you find this useful? Are you still fighting with another XPATH functionality to completely move your tests to CSS? Let us know about it in the comments.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsaucelabs.com%2Fblog%2Findex.php%2F2010%2F03%2Fselenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class%2F&amp;title=Selenium%20Tips%3A%20Finding%20elements%20by%20their%20inner%20text%20using%20%3Acontains%2C%20a%20CSS%20pseudo-class" id="wpa2a_6"><img src="http://saucelabs.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://saucelabs.com/blog/index.php/2010/03/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Selenium Tips: CSS Selectors in Selenium Demystified</title>
		<link>http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/</link>
		<comments>http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 21:42:42 +0000</pubDate>
		<dc:creator>Santiago Suarez Ordoñez</dc:creator>
				<category><![CDATA[Selenium Knowledge]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css selectors]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[selenium tips]]></category>

		<guid isPermaLink="false">http://saucelabs.com/blog/?p=503</guid>
		<description><![CDATA[This week in Selenium Tip of the Week we explain how CSS Selectors can be used to greatly improve the readability and power of your Selenium test code.]]></description>
			<content:encoded><![CDATA[<p>Following my previous TOTW about <a href="http://saucelabs.com/blog/index.php/2009/10/selenium-tip-of-the-week-start-improving-your-locators/">improving your locators</a>, this blog post will show you some advanced CSS rules and pseudo-classes that will help you move your XPATH locators to CSS, a native approach on all browsers.</p>
<h3>Next sibling</h3>
<p>Our first example is useful for navigating lists of elements, such as forms or ul items.  The next sibling will tell selenium to find the next adjacent element on the page that&#8217;s inside the same parent.  Let&#8217;s show an example using a form to select the field after username.</p>
<pre class="brush:css">
<form>
<input class="username" />&lt;/input&gt;
<input class="alias" />&lt;/input&gt;
</form>
</pre>
<p>Let&#8217;s write  a css selector that will choose the input field after &#8220;username&#8221;.  This will select the &#8220;alias&#8221; input, or will select a different element if the form is reordered.</p>
<pre class="brush:css">css=form input.username + input</pre>
<h3>Attribute values</h3>
<p>If you don&#8217;t care about the ordering of child elements, you can use an attribute selector in selenium to choose elements based on any attribute value.  A good example would be choosing the &#8216;username&#8217; element of the form without adding a class.</p>
<pre class="brush:css">
<form>
<input name="username" />&lt;/input&gt;
<input name="password" />&lt;/input&gt;
<input name="continue" type="button" />&lt;/input&gt;
<input name="cancel" type="button" />&lt;/input&gt;
</form>
</pre>
<p>We can easily select the username element without adding a class or an id to the element.</p>
<pre class="brush:css">css=form input[name='username']</pre>
<p>We can even chain filters to be more specific with our selections.</p>
<pre class="brush:css">css=input[name='continue'][type='button']</pre>
<p>Here Selenium will act on the input field with name=&#8221;continue&#8221; and type=&#8221;button&#8221;</p>
<h3>Choosing a specific match</h3>
<p>CSS selectors in Selenium allow us to navigate lists with more finess that the above methods.  If we have a ul and we want to select its fourth li element without regard to any other elements, we should use nth-child or nth-of-type.</p>
<pre class="brush:css">
<ul id="recordlist">
&lt;p&gt;Heading&lt;/p&gt;
<li>Cat</li>
<li>Dog</li>
<li>Car</li>
<li>Goat</li>
</ul>
</pre>
<p>If we want to select the fourth li element (Goat) in this list, we can use the nth-of-type, which will find the fourth li in the list.</p>
<pre class="brush:css">css=ul#recordlist li:nth-of-type(4)</pre>
<p>On the other hand, if we want to get the fourth element only if it is a li element, we can use a filtered nth-child which will select (Car) in this case.</p>
<pre class="brush:css">css=ul#recordlist li:nth-child(4)</pre>
<p>Note, if you don&#8217;t specify a child type for nth-child it will allow you to select the fourth child without regard to type.  This may be useful in testing css layout in selenium.</p>
<pre class="brush:css">css=ul#recordlist *:nth-child(4)</pre>
<h3>Sub-string matches</h3>
<p>CSS in Selenium has an interesting feature of allowing partial string matches using ^=, $=, or *=.  I&#8217;ll define them, then show an example of each:</p>
<table>
<tbody>
<tr>
<td>^=</td>
<td>Match a prefix</td>
</tr>
<tr>
<td>$=</td>
<td>Match a suffix</td>
</tr>
<tr>
<td>*=</td>
<td>Match a substring</td>
</tr>
</tbody>
</table>
<pre class="brush:css">css=a[id^='id_prefix_']</pre>
<p>A link with an &#8220;id&#8221; that starts with the text &#8220;id_prefix_&#8221;</p>
<pre class="brush:css">css=a[id$='_id_sufix']</pre>
<p>A link with an &#8220;id&#8221; that ends with the text &#8220;_id_sufix&#8221;</p>
<pre class="brush:css">css=a[id*='id_pattern']</pre>
<p>A link with an &#8220;id&#8221; that contains the text &#8220;id_pattern&#8221;</p>
<h3>Matching by inner text</h3>
<p>And last, one of the more useful pseudo-classes, :contains()  will match elements with the desired text block:</p>
<pre class="brush:css">css=a:contains('Log Out')</pre>
<p>This will find the log out button on your page no matter where it&#8217;s located.  This is by far my favorite CSS selector and I find it greatly simplifies a lot of my test code.</p>
<p>Tune in next week for more Selenium Tips from <a href="http://saucelabs.com"></a>Sauce Labs.</p>
<p><tt>Sauce Labs created <a href="http://saucelabs.com/products/sauce-ondemand">Sauce OnDemand</a>, a Selenium-based testing service that allows you to test across multiple browsers in the cloud. With <a href="http://saucelabs.com/products/downloads">Selenium IDE and Selenium RC</a> compatibilities, you can get complete cross-platform browser testing today.</tt></p>
]]></content:encoded>
			<wfw:commentRss>http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
	</channel>
</rss>

