0

我正在练习使用 cssGetValue 方法从特定 Web 元素的 CSS 属性中检索值。如何从 Web 元素中获取 CSS 值?这是我的 HTML 代码:

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

我需要为每个 DIV 获取 CSS 值“清晰”

clear = left
4

1 回答 1

1

你可以尝试使用这个:

 /**
     * @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 . '"');
        }

    }

场景中的布局示例如下:

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

我希望这有帮助。

于 2015-12-09T16:43:42.020 回答