3

I have a HTML <div> element and wish to check if it is left aligned using Selenium. However the float:left CSS property is defined in a CSS class.

Is there any way in which I can access the CSS class attributes through Selenium? Alternately is there any other way to get this value?

<div class="myclass">
...
</div>

In sample.css

.myclass{
   float:left;
}

I was trying to use getEval() - this.page().findElement("foo") to find out a way to get CSS class attributes.

1 Answer 1

1

With webdriver you can use css selektors:

WebElement element = driver.findElement(By.cssSelector(".myclass"));
String float = element.getCssValue("float");

See Javadoc of WebElement

Updated Answer!

Sign up to request clarification or add additional context in comments.

3 Comments

yes, i can do that the way you have mentioned. However, I wish to check (through Selenium) that this <div> element is left aligned. So basically, I need a way to access the 'float:left' CSS property, which is defined in CSS Class 'myclass', through Selenium.
seems a good solution, but we are not using webdriver, so cannot use this solution. i am trying to use getElementPositionLeft and providing a range to detect left aligned. Not a great solution, but using it nevertheless.
Are you sure you're not using WebDriver? findelement() is part of the WebDriver API, not the Selenium RC API.

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.