0

I am doing a exercise with client java to use cssSelector method to retrieve some objects having a particular web element's CSS property. The statement

driver.findElements(By.cssSelector(".item-result .content-main .block-opening")) 

returns all elements from page using the class ".item-result .content-main .block-opening" (refer to my blocks below) and all is fine up to there!

Nevertheless, I only want those which have a property text-indent whose value is -999em. To perform it, I first use

driver.findElements(By.cssSelector(".item-result .content-main .block-opening[text-indent]")) 

to retrieve all elements having a text-indent css property but I realize that no element is matching while I have text-indent property inside my css block.

HTML block
<html id="ng-app" data-ng-app="rwd" data-ng-controller="AppCtrl" lang="fr" class="ng-  
scope">
<head>...</head>
<body>
...
  <span class="block-opening icon-time-filled ng-scope" data-ng-if="bloc.openClosed ==  
'O'">Ouvert</span>
...
</body>
</html>

CSS block 
.item-result .content-main .block-opening {
width: 25px;
color: #a1a1a1;
text-indent: -999em;
}

I was hoping to find exactly what i want to by the use of

driver.findElements(By.cssSelector(".item-result .content-main .block-opening[text-indent='-999em']")) 

Since elements related to text-indent are not found, I am blocked to find those having text-indent to -999em.

Please any help would be appreciated!

4
  • You can't use selectors to find elements by CSS styles. You'll have to determine their styles some other way. Commented Feb 28, 2014 at 14:40
  • Do you know a means please? Commented Feb 28, 2014 at 14:42
  • Sorry I don't - otherwise I would have answered. Commented Feb 28, 2014 at 14:51
  • I guess the only way would be to use JavaScript/jQuery which is a terrible idea. I'd suggest using a different mechanism to physically find those elements. Commented Feb 28, 2014 at 15:11

2 Answers 2

1

Perhaps a little bit of a longer route but you could try getting a list of all the elements and checking the css-properties, with the appropriate method.

List<Webelement> elements = driver.findElements(By.cssSelector(".item-result .content-main .block-opening"));
for (Webelement element : elements) {
    if (element.getCssValue("text-indent").equals("-999em")) {
        return element;
    }
}

Caveat, I've never tried to get the text-indent value, as such I can't guarantee that the above will work.

http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebElement.html#getCssValue(java.lang.String)

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

Comments

0

You can locate that element using xpath using inner text value

By.xpath("//span[text()='Ouvert']")

1 Comment

I really want to access to elements whose text-indent property equal to "999em" to exclude them depending on my test strategy. Besides There are elements from the page which are extended characters and which are only built in CSS. So there are no option to get them?

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.