css locator help with preceding sibling

528 views
Skip to first unread message

DaveJohnson

unread,
Jan 20, 2010, 12:39:31 PM1/20/10
to Selenium Users
Can someone please show me the css locator equivalents of these two
xpaths:
//span[contains(text(), 'Device Groups')]/preceding-
sibling::div
//span[contains(text(), 'Device Groups')]/../..
(which is matching the fieldset)

I have been thinking it is suppose to be something to do with the
tilde, like these, but I can't seem to get them to work:
css=span:contains('Device Groups') ~ div
css=span:contains('Device Groups') ~ div ~ fieldset

Thanks,
-Dave Johnson


html code snippet:
<fieldset id="ext-comp-1079" class="x-fieldset x-panel-collapsed x-
form-label-left" style="width: 588px;">
<legend id="ext-gen480" class="x-fieldset-header x-
unselectable" style="-moz-user-select: none;">
<div id="ext-gen484" class="x-tool x-tool-toggle">
</div>
<span id="ext-gen488" class="x-fieldset-header-
text">Device Groups</span>
</legend>
</fieldset>

DaveJohnson

unread,
Jan 20, 2010, 7:40:12 PM1/20/10
to Selenium Users
So apparently it isn't possible to traverse backwards across ancestors
objects which is what I was trying to do with accessing the fieldset
object. Most annoying but its always something, right? :) Still not
positive on a preceding-sibling for css but its looking unlikely, I
guess I'll default to xpath, and move on. If you have anything
though, please share it.

http://stackoverflow.com/questions/2000582/css-selector-for-foo-that-contains-bar

Aditya Ivaturi

unread,
Jan 21, 2010, 2:48:19 PM1/21/10
to Selenium Users
Yes, that is a problem with CSS. But you should be aware that if you
use locators intensively, XPaths are going to be slow on IE - there
are workarounds & solutions though.

Anthony Long

unread,
Jan 22, 2010, 2:15:06 AM1/22/10
to Selenium Users
if the xpath location of these items doesnt change use xpath. have a
conditional that if the lookup fails, try the css locator, which you
can find with firebug, or numerous other addons. If you feel the
problem is IE specific, use the web developer toolbar and use the
identifier from IE in your conditional.

alternately, there is probably an xpath node count you can use,
atleast 2-4 javascript commands i can think of that would work, and
probably hundreds of programming language specific options available.

Reply all
Reply to author
Forward
0 new messages