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