我想用PHPUnit Selenium選擇一個iframe,但不知怎的,它似乎不工作。這是代碼:PHPUnit - Selenium 2:如何選擇沒有ID和名稱的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,但不知何故$這個 - >框架($ 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}]
你知道爲什麼嗎?
我得到一個錯誤:PHP致命錯誤:調用一個成員函數getDriver()一個非對象 - 恍如session不存在 – rochadk 2013-04-09 16:18:53
我不是PHP。基本上我來自Java背景。在Java中有一個名爲driver.switchTo()。frame(0)的函數;'希望在PHP中應該有一個等價的方法。我從Google獲得了上述解決方案。 – Hemanth 2013-04-09 16:24:57
好的,我猜測等效函數將是$ this-> frame($ index),但這也不起作用。感謝您的幫助:) – rochadk 2013-04-10 05:08:48