2

When i am trying to locate this below div with class name,i am unable to find,

<div class="large 20 columns">..</div>

i tried dr.findElement(By.cssSelector("div.large.20.columns']"));but unable to locate.

Please let me know, is there any way to locate class name with space using CSS Selector.

J_Coder
  • 625
  • 3
  • 12
  • 22

3 Answers3

2

The problem here is that the "20" class expects you to use a class selector like .20, which is not a valid selector as CSS idents must not start with a digit.

This should work:

dr.findElement(By.cssSelector("div.large.\\20.columns"));

You also have '] at the end of your selector string for some reason. Was this a leftover from an attempt at using an attribute selector? If so, you should be able to get away with this as well but only if the page is guaranteed to have the class names in that exact order:

dr.findElement(By.cssSelector("div[class='large 20 columns']"));
BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
1

Relying on layout-oriented class names like large is not a good idea in general. I would use just:

div.columns

If this is not enough to uniquely identify the element, I would additionally check for other attributes, specific parent, child or adjacent elements.

alecxe
  • 414,977
  • 106
  • 935
  • 1,083
0

You are not able to find the element because of invalid class name. CSS class can not start with a number(20 in your case). Also, CSS class names can not have spaces as they are considered to be different classes.

Please refer to the explaination provided here and here

Community
  • 1
  • 1