Selenium AndroidDriver - 无法切换到iframe“无法读取未定义的属性'文档'

时间:2013-06-06 22:02:17

标签: ruby selenium webdriver selenium-webdriver

我无法切换到AndroidDriver内部的iframe。详情如下。我已经尝试使用firefox的常规webdriver,我可以切换到正常。

代码:

require "selenium-webdriver"
require "selenium/client"

include Selenium::WebDriver::DriverExtensions::HasTouchScreen

caps = Selenium::WebDriver::Remote::Capabilities.android
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 480
driver = Selenium::WebDriver.for(
  :remote,
  :url => "http://localhost:8080/wd/hub",
  :http_client => client,
  :desired_capabilities => caps)

driver.navigate.to "some page with iframe"

driver.switch_to.frame "engagement-iframe"

堆栈跟踪:

Selenium::WebDriver::Error::UnknownError: Error: {"message":"Cannot read property 'document' of undefined"}
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Linux', os.arch: 'armv7l', os.version: '3.0.31-789635', java.version: '0'
Driver info: driver.version: AndroidWebDriver (org.openqa.selenium.WebDriverException)
    from [remote server] org.openqa.selenium.android.library.AndroidWebDriver(AndroidWebDriver.java):997:in `throwIfError'
    from [remote server] org.openqa.selenium.android.library.AndroidWebDriver(AndroidWebDriver.java):868:in `executeRawScript'
    from [remote server] org.openqa.selenium.android.library.AndroidWebDriver(AndroidWebDriver.java):858:in `access$7'
    from [remote server] org.openqa.selenium.android.library.AndroidWebDriver$AndroidTargetLocator(AndroidWebDriver.java):679:in `frame'
    from [remote server] org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringTargetLocator(EventFiringWebDriver.java):573:in `frame'
    from [remote server] org.openqa.selenium.remote.server.handler.SwitchToFrame(SwitchToFrame.java):52:in `call'
    from [remote server] org.openqa.selenium.remote.server.handler.SwitchToFrame(SwitchToFrame.java):1:in `call'
    from [remote server] java.util.concurrent.FutureTask$Sync(FutureTask.java):305:in `innerRun'
    from [remote server] java.util.concurrent.FutureTask(FutureTask.java):137:in `run'
    from [remote server] org.openqa.selenium.remote.server.DefaultSession$1(DefaultSession.java):151:in `run'
    from [remote server] java.util.concurrent.ThreadPoolExecutor(ThreadPoolExecutor.java):1076:in `runWorker'
    from [remote server] java.util.concurrent.ThreadPoolExecutor$Worker(ThreadPoolExecutor.java):569:in `run'
    from [remote server] java.lang.Thread(Thread.java):856:in `run'

1 个答案:

答案 0 :(得分:0)

我的测试遇到了同样的问题,我猜这个行为会在ChromeDriver上重现。

我的解决方法(一种丑陋的解决方法)是将iframe视为一个独立的窗口。

听到您对此WebDriver错误的解决方案非常棒