Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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
不带id/名称的貂皮/behat iframe_Iframe_Behat_Mink_Setattribute - Fatal编程技术网

不带id/名称的貂皮/behat iframe

不带id/名称的貂皮/behat iframe,iframe,behat,mink,setattribute,Iframe,Behat,Mink,Setattribute,我必须验证没有名称/id的iframe中的文本/消息。探索之后,我找到了添加id/名称并使用switchToIFrame(id/名称)的解决方案。如何在mink中为节点元素设置id/name?NodeElement中不支持SetAttribute()方法,框架不支持setValue() <html> <body> <div class="div1"> <iframe class="xyz"> <!DOCTYPE

我必须验证没有名称/id的iframe中的文本/消息。探索之后,我找到了添加id/名称并使用switchToIFrame(id/名称)的解决方案。如何在mink中为节点元素设置id/name?NodeElement中不支持SetAttribute()方法,框架不支持setValue()

<html>
  <body>
    <div class="div1">
    <iframe class="xyz">
      <!DOCTYPE html>
      <html>
        <body>
          <div class="frame"></div>
          <p>The paragraph1</p>
        </body>
       </html>
  </body>
</html>

要将id/name设置为iframe,可以使用javascript

创建一个类似switchToIFrameBySelector($iframeSelector)的方法,等待给定元素可用,然后可以执行javascript代码为iframe和使用switchToIFrame方法后设置名称/id

要执行js脚本,可以在try catch中使用executeScript方法,并在需要时抛出自定义异常

公共函数切换到帧($iframeSelector){
$function=getMessage());
抛出new\Exception(“未找到元素$iframeSelector。”.PHP_EOL.$e->getMessage());
}
$this->getSession()->getDriver()->switchToIFrame(“iframeToSwitchTo”);

}
输入数字或for循环以迭代需要哪一个,然后设置数字与交叉原点一起工作


$this->getSession()->getDriver()->switchToIFrame(0)

我假设这只是一个测试方法,否则切换到iframe和验证应该是不同的步骤,预期的文本和包含此文本的选择器应该是metod的参数。我从您的其他答案中找到了此解决方案。有没有办法在PHP中做到这一点?如果不使用js/jQuery,我不这么认为。我看到Selenium2Driver中有一个方法setValue,它也使用js脚本。可能没有方法更改页面/元素,因为您不应该进行这些类型的更改,setValue用于设置文本字段/输入的值。你对使用js有什么限制吗?您应该只与页面交互,而不更改页面,使用js是一种特殊情况下的变通方法。如果可能,您应该与项目的开发人员交谈,添加一些属性。我将尝试使用此解决方案,看看我的问题是否得到解决。我也将张贴我的代码后,我成功地在这方面。非常感谢。很好用,谢谢。公共函数iSwitchToIframe($arg1){$function=getSession()->getDriver()->switchToIFrame(“iframeToSwitchTo”);}catch(异常$e){throw new\InvalidArgumentException(sprintf(“捕获的异常:%s”,$e->getMessage());}这不是这个方法的工作方式。在查看实现时,参数必须是用于搜索命名iFrame的字符串。此解决方案将导致错误。
public function iShouldSeeDescription($arg1)
{
    $expected = "The paragraph1";
    $iframe=$this->getSession ()->getPage ()->find ( 'xpath', '//div[contains(@class,"div1")]/iframe[contains(@class,"xyz")]');
    $iframe->setAttribute('id', 'iframe_id');
    $iframeId = $iframe->getAttribute('id');
    $this->getSession()->switchToIframe("$iframeId");
    $actual = $this->getSession()->getPage()->find('xpath', '//div[@class="frame"]/p[1]');
    if ($actual === null) {
        throw new \InvalidArgumentException ( sprintf ( 'null:%s', $arg1 ) );
    }
    if (!($actual === $expected)) {
        throw new \InvalidArgumentException ( sprintf ( 'The Acutal description:%s and expected description:%s did not match ', $actual, $expected ) );
    }

}