Unable to manipulate click in IFrame using Android WebDriver

I am writing a test for a hybrid app which contains an iframe and I’m trying to click a button inside the iframe.

It worth mentioning that the data inside the iframe is in another origin. Nevertheless, I managed to switch to the iframe and I can see the content of it.

This is the command I run:


It work fine on an iOS simulator, but on the Android it does nothing. The test continue to run, but not action is made.

I’m running Appium 1.2.2 with nodejs wd client and Genymotion 2.2.2

I have faced the same issue. I was frustrated :frowning:

I have tried to execute this


It returns the same content before and after switching to frame, so desired element is not found by Android Driver although actually we see it.

I have not enough time to reproduce it on Android SDK emulator. @shlomitc, have you tried? Is it reproduced?
I think it is an issue of the working with chromedriver (it is actually used). Tomorrow I will report this issue. Or… @shlomitc, could you report this issue here

I opened an issue here: https://github.com/appium/appium/issues/3759
I also tried it on a real android device and on the Andorid SDK emulator - none of them worked.

Well, I managed to work around it. I used xpath to find the element and then used tapElement() to make the magic happen.

return driver
  .contexts().then(function (contexts) { 
    return browser.context(contexts[1]); // choose the webview context
  .frame('myFrame") //switch to iframe
  .elementByXPath('//li[div/span[contains(text(),"Data I want")]]')
    return driver.tapElement(el);

This is definitely not perfect, also because the following variation (chaining promises) is not working:

.elementByXPath('//li[div/span[contains(text(),"Data I want")]]').tapElement()

Do you have any solution for this issue

As written in my last post, use contexts() to get the contexts list, then context(<the context name>) to switch to the wanted context (from native to Webview in my case).
Then, switch to the wanted iframe using frame(<frame id>).
Now you’re pointing to the wanted iframe your webview.
now you can use tap() on the last element:

.elementByXPath('//li[div/span[contains(text(),"Data I want")]]').tap()

You can use any other strategy to make it work such as elementById(), elementByClassName() etc…

I tried the approach that you mentioned, but no luck.

I am getting the WEBVIEW in runtime using the below code and assigning it to driver in the runtime

       Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {

    if(contextName.contains("WEBVIEW")) //getting either webview_1 or webview_2 



getting below exception
Exception in thread “main” org.openqa.selenium.WebDriverException: ‘undefined’ is not an object (evaluating ‘b.querySelector’) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 62 milliseconds
Build info: version: ‘2.43.1’, revision: ‘5163bce’, time: ‘2014-09-10 16:27:33’
System info: host: ‘N/A’, ip: ‘N/A’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.9.5’, java.version: ‘1.7.0_71’
Session ID: 28cc78cb-c9b9-4097-854d-cf6a28f0dfb5
Driver info: io.appium.java_client.AppiumDriver

Is it iOS?

I have found the issue

But it is supposed to be an issue of chromedriver. Does SafariDriver works with WEBVIEV on iOS? It is possible that SafariDriver cann’t work with frames in WEBVIEV :frowning:

yes, it’s IOS with Safari browser. I had this issue when I try to execute the selenium script using Appium in Mobile Safari browser. Where as the same script, I am able execute in Mac Desktop with Safari Browser and Windows desktop with IE, Chrome and Firefox. I think it’s an issue with Appium.

So you can report a new found issue here: https://github.com/appium/appium/issues

Please add to description logs from Appium server. It is better if you create a gist ( https://gist.github.com ) and attach this link to description.

You can refer to the issue above, but issue of chromedriver is suspected there.