dongsu3664 2015-09-02 13:23
浏览 37

如何使用BEHAT / MINK(getCssValue)PHP从特定Web元素的CSS属性获取值

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
  • 写回答

1条回答 默认 最新

  • doufu1950 2015-12-09 16:43
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站