How to handle redirects to a browser from an app with appium

Hello,

I would like to know how to handle redirects to a browser from native app using appium.
For example, with the app I am automating, it redirects me to a browser for “Forgot Password” / “Manage Account” options.
When redirect happens, the scripts start to fail as it cannot recognise elements on the browser

Environment:

  • Appium - 1.4.0

  • app on Android real device

  • OS - Windows 7

  • language binding - python

  • Do we have to update device capabilities when the redirect happens? If so how ?
    Please help

Thanks,
Sunil

you need to switch to webview context once you open the browser.

Thanks for your Reply.
But there is no WEBVIEW context present. When i run, self.driver.contexts i get [u’NATIVE_APP’].
Go this exception when i ran, self.driver.switch_to.context(‘WEBVIEW’)
NoSuchContextException: Message: No such context found.

appium_20150608_161853.log (917.1 KB)

Attached appium log

Print a page source to see if there is a webview element in your page, If so there might be some issue with Chromedriver.

@sebv
Thanks for your reply and sorry for the delay in response.
Yes i do see WebView element in page source.
Which logs could show me errors in Chromedriver?

After switching to WebView how can i inspect the element as UI Automator is not able to find the Webview.

Example:In My App I have one button Login Through Facebook.Once I tap on the button it opens the webview.Now How can I find the Username field and Password And login button.

Is there any way of finding the elements

What I usually do:

System.out.println(driver.getPageSource());

and you get the page structure printed in the console. There is no WEB context, that’s only when you have a hybrid app…

For example, if I want to check the current URL, this works for me:

driver.findElementById(“com.android.chrome:id/url_bar”).getText()

Thank i Vicusbass,but i did nt get ur ans how to write script for the element in webview

Well, at this point, you’re in the browser, right? You need to validate some element IN THE BROWSER. The browser itself is just an app, so you can print the hierarchy and that’s just an XML file where you can find the elements and work with it. You don’t need the Inspector for that…

1 Like

Thank u.I will Try as u said

I am unable to start the appium server with no reset mode.every time it installs the app.In settings everything is in disabled mode so i am unable to select the checkbox.can anybody help me doing this.

I am unable to start the appium server with no reset mode.every time it installs the app.In settings everything is in disabled mode so i am unable to select the checkbox.can anybody help me doing this.

I have this in capabilities when I don;t want to reset the app

capabilities.setCapability(“noReset”, true);

1 Like

Thank u so much .It worked for me