我正在尝试使用 PHPUnit Selenium 选择一个 iframe,但不知何故它似乎不起作用。这是代码:
<body>
...
<div id="container">
<iframe src="x.html">
<html>
...
<body></body> <!-- this is the body I would like to get -->
...
</html>
</iframe>
</div>
...
</body>
和 PHP:
<?php
class Test extends PHPUnit_Extensions_Selenium2TestCase {
public function testIframe() {
$theFrame = $this->byCssSelector('#container iframe');
$this->frame($theFrame->getId());
$this->byCssSelector('body')->text('test');
}
}
如果我检查 $theFrame 变量,它是一个 id=5 的 PHPUnit_Extensions_Selenium2TestCase_Element,但不知何故 $this->frame($theFrame->getId()) 会抛出一个错误:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: Unable to locate frame: 5
Command duration or timeout: 32 milliseconds
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:52:59'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-39-generic',
java.version: '1.7.0_17'
Session ID: 0192c3aa-d4a2-4c9d-bcca-bbd7139dd8c3
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, databaseEnabled=true, cssSelectorsEnabled=true,
javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox,
browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true,
rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true,
takesScreenshot=true, version=20.0}]
你知道为什么吗?