我想写一个测试登录一个网站。问题是当我点击登录弹出窗口出现,这是一个iframe。现在我写代码切换窗口。但我切换到不同的iframe。我不知道它来自这里是一个代码片段。我使用 selenium WebDriver写的Facebook。
<?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
}
}
?>
1条答案
按热度按时间slhcrj9b1#
要与frame或iframe中的元素交互,请先切换到该frame!
请参见wiki。https://github.com/facebook/php-webdriver/wiki/Alert,-窗口选项卡,-框架iframe-和-活动元素#框架iframe