I want to get the class name inside the div element by xpath.
<div class="indicator true"></div>
And I want to check if the class nams equals to "indicator true". Any help?
I want to get the class name inside the div element by xpath.
<div class="indicator true"></div>
And I want to check if the class nams equals to "indicator true". Any help?
And I want to check if the class nams equals to "indicator true". Any help?
Yes, there is help.
driver.findElement(By.xpath("//div[@class = 'indicator true']")) .click();
That said, I am not sure what your intention is. Because you also say:
I want to get the class name inside the div element by xpath.
The path expression above returns a div
element, not the class name.
You can access the class value of the div element by using the WebElement.getAttribute() - Method.
Your Problem is to get the div element without the class as part of the selector.
I suggest to add an id attribut to the div and select the div by id selector. Then you can check class value.
WebElement divElem = driver.findElement(By.id("someId"))
assert divElem.getAttribute("class").equals("indicator true");
//*[contains(concat(" ", normalize-space(@class), " "), " foo ")]
source : Selecting a css class with xpath
you can use the getAttribute() and enter the identify name in the brackets this will return you the identify value. the following code should return you "indicator true":
assert divElem.getAttribute("class");