IOS WebView findByXPath click() does not work

Hi,

we are testing a hybrid app with simulator of “IPad Air 2 9.2” using Appium 1.5.3. Within the webview there is an element like this:

<div tabindex="0" class="button" id="textfield">
<input type="text">
<div class="button-label">Textfield</div>
</div>

With the selenium IDE (within FireFox) it is possible to find the element with an xPath and click on the inner div where it seems this is a kind of a button (with javascript) see my xPath within Selenium IDE:

click //div[@id=‘textfield’]/div

With Appium we switch to the corresponding webview context and wanna click the same element with this function and same xPath:

elements = (List)driver.findElementsByXPath("//div[@id=‘textfield’]/div");
elements.get(0).click();

or short

findElementByXPath("//div[@id=‘textfield’]/div").click();

It seems that appium found the element but does not do the click and we can’t figure out why it works with the selenium IDE but not with the Appium function!!!

Furthermore we extracted an xPath out of the Appium Inspector and it work with the appium function see this one:

//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[2]

But we need the first solution for a fine workflow.

We are very pleased if anyone can help

Thanks!

Are you switching to the web view context before attempting to interact with the web view element? Hybrid Apps start in the NATIVE_APP context and you must switch the context once your app moves into the web views.

Yes, I do switch to the right web context. I mentioned it in my last post under the xPath expression. The weird thing is this xPath works with the selenium IDE but not with appium. It seems that appium can find the element but do not click on it.

Some more information:
Our driver instance is of type IOSDriver and our element of type IOSElement. I don’t know if it belongs to this. But it shouldn’t cause its derived from AppiumDriver which is derived from RemoteWebDriver.

I also tried another xPath which works with the Selenium IDE but not with appium see:
//div[@class=‘button-label’ and contains(text(),‘Textfield’)]

The only xPath which seems to work is:
//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[2]
But I don’t get the clue why!

Questiion!
Maybe the markup of the website within the webview differs to the desktop version. Is there a good way to get the source html out of the webview? Maybe with the appium log?

Some clearification!

Meanwhile I could talk to a developer of the website. And he told me that the mobile version of the site works a little bit different as the desktop version.

The inner div on the desktop version is registered with a click listener. On the mobile the parent div is registered with a touch listener.

But unfortunately it is not possible to perform the touch listener of this element with the click() function of appium.

So I tried the tap(1,20) function and got the error message:

org.openqa.selenium.WebDriverException: Method has not yet been implemented

Maybe this is related to appium 1.5.3?
On another machine I will try to update to appium 1.6x

Only for completness
The developer could provide me a version of the website where the click listener is set to the inner div. And appium was now able to do the click(). But we need to click the touch listener of the parent div!