Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHPUnit Selenium2TestCase中单击可见元素?_Php_Selenium_Phpunit_Acceptance Testing - Fatal编程技术网

如何在PHPUnit Selenium2TestCase中单击可见元素?

如何在PHPUnit Selenium2TestCase中单击可见元素?,php,selenium,phpunit,acceptance-testing,Php,Selenium,Phpunit,Acceptance Testing,我有两个同名的按钮。出于设计原因,同时只能看到其中一个 我想点击任何可见的按钮 如果隐藏第一个按钮,则此表达式 $this->byCssSelector('[name="saveAndClose"]')->click() 返回 Element is not currently visible and so may not be interacted with 如何单击可视按钮?我已经为此编写了简单的代码 public function clickOnDisplayedElemen

我有两个同名的按钮。出于设计原因,同时只能看到其中一个

我想点击任何可见的按钮

如果隐藏第一个按钮,则此表达式

$this->byCssSelector('[name="saveAndClose"]')->click()
返回

Element is not currently visible and so may not be interacted with

如何单击可视按钮?

我已经为此编写了简单的代码

public function clickOnDisplayedElementByName($name)
    {
    $elements = $this->elements($this->using('css selector')->value('[name="' . $name . '"]'));
    foreach ($elements as $element)
        {
        if ($element->displayed())
            {
            $element->click();
            return;
            }
        }
    $this->fail('There is no visible elements with name ' . $name);
    }