2
我想寫測試登錄一個網站。問題是當我點擊登錄時出現了一個是iframe的彈出窗口。現在我編寫代碼在窗口之間切換。但我切換到不同的iframe。我不知道它來自哪裏這是一段代碼。我使用Facebook編寫的selenium WebDriver。如何切換到硒的PHP框架PHP單位
<?php
class TitleTest extends PHPUnit_Framework_TestCase {
protected $webDriver;
public function setUp()
{
$capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox');
$this->webDriver = RemoteWebDriver::create('http://ip-address:4444/wd/hub', $capabilities);
}
protected $url = 'https://mywebsite.net';
public function testAfterLoginBudliTitle()
{
// Sell used Login and account page's title assert
$this->webDriver->get($this->url);
$this->webDriver->manage()->window()->maximize();
$link = $this->webDriver->findElement(WebDriverBy::xpath('/html/body/div[3]/header/div[2]/div/ul/li[2]/a'));
sleep(2);
$link->click(); //click on login
sleep(3);
$iframe = $this->webDriver->findElement(WebDriverBy::tagName('iframe'));
$frameName = $iframe->getAttribute('name');
//Switch the driver to the iframe
$this->webDriver->switchTo()->frame($frameName);
$this->assertContains('demo', $frameName); // Here I get the different iframe name
}
}
?>
我們使用$ this-> frame(0); ,對於phpunit-selenium框架,我不確定Facebook庫,但你可以像這樣搜索相似 – Deep123 2014-12-15 05:32:42