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?

4 Answers 4

2

Move to your element and click. Example:

new Actions(driver).MoveToElement(yourElement).Click().Perform();
Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

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.
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!!

Comments

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.