Selenium RC 访问 iframe 中元素的问题

// Selenium Client: selenium-java-2.34.0

// Selenium Server: selenium-server-standalone-2.34.0.jar

// 系统版本:Windows 7 64-bit

 

在 Eclipse 中执行 Selenium 测试脚本,若 Selenium RC 直接访问 iframe 中的元素,可能会出现找不到 locator 对应的元素的错误,类似异常描述如下:

com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the user group at https://groups.google.com/forum/#!forum/selenium-users for error details from the log window. The error message is: 无法获取属性“nodeValue”的值: 对象为 null 或未定义

解决方法为:在访问 iframe 元素之前,先使用 selectFrame("frameID") 方法定位相应的 Frame ,再执行其中的元素的操作,最后使用 selectWindow(null) 跳出回到默认的页面框架。

 

以下浏览器在执行 selectFrame("frameID") 方法时可能会出现如下问题:

IE (v9): 

com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. The error message is: 拒绝访问。

Chrome (v28):

com.thoughtworks.selenium.SeleniumException: ERROR: Element *** (frameID) not found

Opera (12):

com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. The error message is: Security error: attempted to read protected variable: seleniumMarker1376017809917

这是因为当Selenium RC 访问 iframe 元素会产生 JavaScript 跨域问题,因此会涉及到安全机制问题,有些浏览器会对此进行一定的限制。

 

最有效的解决方法为,使用 WebDriver 切换到 iframe , 对应方法为 driver.switchTo().frame("frameID"), 跳出 iframe 对应方法为 driver.switchTo().defaultContent().

 

参考资料:

http://aboutselenium.blogspot.com/2011/10/identify-iframe-and-dealing-problems.html

http://stackoverflow.com/questions/9942928/handling-iframe-in-webdriver

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值