Issue Details (XML | Word | Printable)

Key: SEL-698
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Justin Meyer
Votes: 3
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Selenium

nth-child selectors do not work correctly

Created: 04/Aug/09 10:36 PM   Updated: 10/Sep/09 02:07 AM
Component/s: BrowserBot-Mozilla
Affects Version/s: 1.0-beta-2
Fix Version/s: None

Environment: 1.0.0 on Windows XP, FF3


 Description  « Hide

From the Java API a nth-child selector followed by refining selectors does not work. For example:

".recipe:nth-child(2) a.edit"

however:

".recipe:nth-child(2)" does work.

I'm going to try 1.0.1 and see if this helps.



Sort Order: Ascending order - Click to sort in descending order
Levi Cameron added a comment - 09/Sep/09 10:36 PM

Demonstration test case of failure:

<html>
<head>
<style type="text/css">
.level1:nth-child(1) .level2 { background: yellow; }
</style>
</head>
<body>
<div class="level1">
<div class="level2">item1</div>
</div>
</body>
</html>

(Tested on Selenium IDE 1.0.2 + FF3.5.3)

===== Fails:
assertText
css=.level1:nth-child(1) .level2
item1

===== Succeeds:
assertText
css=.level1 .level2:nth-child(1)
item1


Levi Cameron added a comment - 10/Sep/09 02:07 AM

The bug appears to be in the cssQuery library used by Selenium.
When parsing any psuedoselector with parentheses, all whitespace
immediately following a trailing parenthesis is incorrectly stripped,
altering the expression.

(Can be demonstrated in the example above, where ".level2:nth-child(1) .level2"
incorrectly matches the inner div when it should match nothing)

If cssQuery.js is modifed:

diff selenium\lib\cssQuery\src\cssQuery.js:

@@ -317,7 +317,7 @@
return $selector.match(STREAM) || [];
};

-var WHITESPACE = /\s*([\s>+~(),]|^|$)\s*/g;
+var WHITESPACE = /\s*([\s>+~(,]|^|$)\s*/g;
var IMPLIED_ALL = /([\s>+~,]|[^(]+|^)([#.:@])/g;
var parseSelector = function($selector) {
return $selector

Then it works. Have submitted a patch to the author of cssQuery, but in the
meantime this may help anyone affected.