tags:

views:

31

answers:

1

Hi guys!

I know that selenium can use css locators.

I know that the syntax is something like this:

xpath=//div[@id,'topLeft')//span[contains(@class,'name')]
or css=#topLeft .name

Now, what if .name is like this: //span[contains(@class,'name with space')]

Then it would fail... HOw to look for a locator that has space in it?

Thanks!

EDIT Solution: css=span.name.with.space

+2  A: 

Class names can't have spaces. However, you can define multiple classes for a single element by putting a space between them. Take a look at the id and class identifiers section in the HTML spec for more.

You should be able to use the CSS locator by using only one of the classes.

If that doesn't work, double check your CSS selector using a tool like Firefinder for FireBug. I was able use Selenium-IDE with an element that had two classes. For the HTML

<div class="c1 c2">
    <span class"s1">Test</span>
</div>

I used the selector

css=div.c1 span
pnewhook
Yeah. Say that to the devs at my company who have class names like this: button AddComment IntegrationButton.
Hannibal
I'm not saying there can't be spaces. I'm pointing out that those aren't all one class. Those are individual classes. If you're trying to identify one with a selector, just pick a class.
pnewhook
Now i'm the one who is dumb... I never thought that an element can have multiple classes? Damn... I learn something new everyday. :) That means if i see a class name like this: "button Something submitter"... That that element has button class Something class and submitter class? And if i search for button class then this one will also be found?
Hannibal
But what if there are more c1 and c2 around alone but only one element with booth classes? And i need THAT element?
Hannibal
I can simply use + to add class names. Thanks. :)
Hannibal
That is NOT true... Adding classes to selectors is with DOT notation. Like:css=div#ClassName a.button.major.moreClassname
Hannibal