【发布时间】:2015-10-07 18:40:11
【问题描述】:
我正在努力验证 html 对象标签中的 html 元素。
以下是我的测试 html (test1.html)。
<html>
<body>
<h1>this is test 1</h1>
<object id='obj1' width="100%" height="200px" data="http://www.w3schools.com/"></object>
<br> <br> <br> <br>
<iframe id='ifr1' width="100%" height="200px" src="http://www.w3schools.com/"></iframe>
</body>
</html>
iframe的情况下,使用webdriver switchto frame方法就可以轻松处理,如下例。
@Test
public void testIframe() {
try {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://localhost/test1.html");
driver.switchTo().frame(0);
Assert.assertTrue(driver.findElement(By.xpath("/html/body/div[1]/div")).getText().equals("THE WORLD'S LARGEST WEB DEVELOPER SITE"));
driver.quit();
} catch (Exception e) {
e.printStackTrace();
}
}
但在对象标签的情况下,switchTo 方法不能以相同的方式应用。
我很好奇 Selenium 提供了这种处理方式。
有没有人想办法解决这个问题,或者有什么建议?
【问题讨论】: