Mobile: scrollTo fails in iOS hybrid webview

I finally had time to work on this some more and thought I’d share what I’ve found thus far in case anyone else has the same issue. Or reads this and offers something different.

Note I’m testing on the iOS8 simulator only at this time, not Android at all yet.

The solution appears to be to simply switch to the webview context self.driver.switch_to.context('WEBVIEW_1') prior to attempting to interact with the webview elements. Then remember to switch back to the native app context self.driver.switch_to.context('NATIVE_APP') prior to interacting with the native elements the webview is wrapped in.

Once you switch to the webview context the contents of which are then accessed just like they would using native Selenium. You can get the page source self.driver.page_source and see the full HTML.

So, instead of doing this in the native context:

self.driver.find_element_by_xpath('//UIAlink[@name="Hello, are you the text I'm looking for?"]').click()

You use this in the webview context:

self.driver.find_element_by_xpath('//a[text()="Hello, are you the text I'm looking for?"]').click()

And when invoking a click on the webview element Appium will now (just like it does for native elements) happily automatically scroll any out-of-view elements into view prior to clicking on it.

This is casually described here: http://appium.io/slate/en/v1.0.0/?ruby#automating-hybrid-apps Too bad I didn’t read that a couple of weeks ago. :smile:

1 Like