【发布时间】:2016-07-29 20:43:26
【问题描述】:
我必须在没有名称/ID 的情况下验证 iframe 中的文本/消息。经过探索,我发现了添加 id/name 并使用 switchToIFrame(id/name) 的解决方案。如何将 id/name 设置为 mink 中的节点元素?节点元素中不支持 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>
我的上下文文件是
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 ) );
}
}
【问题讨论】:
-
我假设这只是一种测试方法,否则切换到 iframe 和验证应该是不同的步骤,预期的文本和包含此文本的选择器应该是方法的参数。
标签: iframe behat mink setattribute