10

I have this button:-

 <div class="dsk-col-1-4 card new">
    <div class="div_center_div">
      <span class="icon icon_plus-black-symbol"></span>
      <h2>Create</h2>
    </div>
  </div>

But I tried with find element by classname:-

driver.findElementByClassName("dsk-col-1-4 card new").click();

But it does not work. Any help?

Razia sultana
  • 2,168
  • 3
  • 15
  • 20
Oscar Ubillús
  • 150
  • 1
  • 2
  • 13

4 Answers4

2

Move to your element and click. Example:

new Actions(driver).MoveToElement(yourElement).Click().Perform();
Das_Geek
  • 2,775
  • 7
  • 20
  • 26
Gkumarap
  • 21
  • 2
1

The "by class name" locator usually expects a single class name to be passed:

driver.findElementByClassName("card").click();

If you want to use multiple classes, go with a "by CSS selector"

driver.findElementByCssSelector(".card.new").click();

Note that the dsk-col-1-4 class is not a very good choice for an element locator - this looks very much like a layout-oriented class name which not only have a higher probability to b changed, but also does not bring any information about the element and it's purpose. card and new on the other hand are a better fit.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • i get the css from that element : driver.findElementByCssSelector("html body div.main div.addon_cards.fluidwrap div.dsk-col-1-4.card.new").click(); but it does not works. – Oscar Ubillús Dec 19 '16 at 20:39
1

Ok so I couldn't understand exactly Which element you want to click on, So based on my assumption , try below Xpaths :

1) if it is <div class="dsk-col-1-4 card new"> that you want to click

//div[contains(@class,'dsk-col-1-4 card new')]

2) If it is that you want to click,

//span[contains(@class,'icon icon_plus-black-symbol')]

3) If it is <h2>Create</h2> that you want to click,

//h2[text()='Create']

Hope this Helps!!

Arpan Buch
  • 1,380
  • 5
  • 19
  • 41
0

Within your locator you're passing multiple class names, and although they are both assigned to the element the findElementByClassName function realy only works when it is a single class name. The way I'd do it would be to use findelement(By.Xpath()), in this instance you'd need to use

webDriver.findElement(By.xpath("//div[contains(@class,'dsk-col-1-4 card new')]")).click();
Jsmith2800
  • 1,113
  • 1
  • 9
  • 18