0

I am doing a exercise to use cssGetValue method to retrieve the value from a particular web element's CSS property. How to get CSS value from web element? this is my HTML code:

<div class="odd content-grid-0 content-grid-item">
<div class="even content-grid-1 content-grid-item impression-pixel-processed">
<div class="odd content-grid-2 content-grid-item">
<div class="even content-grid-3 content-grid-item">
<div class="odd content-grid-4 content-grid-item">
<div class="even content-grid-5 content-grid-item">
<div class="odd content-grid-6 content-grid-item">
<div class="even content-grid-7 content-grid-item">
<div class="odd content-grid-8 content-grid-item">

I need to get CSS value 'clear' for each DIV

clear = left
Ihor Bovkit
  • 120
  • 3
  • 9

1 Answers1

1

You could try using this:

 /**
     * @Then /^I should see "([^"]*)" in the "([^"]*)" attribute of the "([^"]*)" element$/
     */
    public
    function iShouldSeeInTheAttributeOfTheElement($content, $attribute, $elementCSS)
    {
        $page = $this->getSession()->getPage();
        $element = $page->find("css", $elementCSS);
        if (!$element) {
            throw new Exception($elementCSS . ' does not exist');
        }


        $attributeValue = $element->getAttribute($attribute);

        if (!$attributeValue) {
            throw new Exception($elementCSS . ' does not have an "' . $attribute . '" attribute');
        } else if (!is_numeric(strpos($attributeValue, $content))) {
            throw new Exception('The "' . $attribute . '" attribute for ' . $elementCSS . ' does not contain "' . $content . '"');
        }

    }

An example of the layout within a Scenario would be this:

Then I should see "left" in the "clear" attribute of the ".content-grid-0" element

I hope this helps.

KyleFairns
  • 2,947
  • 1
  • 15
  • 35
  • Hi Kyle, getAttribute could get attribute that is present on HTML only, but I need to get it from css file. I have added part of HTML code to my question. I have
    and need to get cssValue from css file.
    – Ihor Bovkit May 24 '16 at 09:38
  • @IhorBovkit did you find a solution to this problem? Thanks! – Cristian Romanescu Apr 06 '19 at 09:02