Back to the native app after Facebook WebView connect

Hi everyone !

I got an issue, and after scanning the web I still don’t find the solution…

I use a native app with the Facebook WebView connect. After the connection, I got the alert “Open this page in…” with the two options “Cancel” and “Open”. My problem is that I can’t back to my native app.

Here my code :

Set<String> contextNames = AppiumTest.driver.getContextHandles(); for (String contextName : contextNames) { System.out.println(contextNames); } AppiumTest.driver.context(String.valueOf(contextNames.toArray()[1])); System.out.println(AppiumTest.driver.getCapabilities()); log("Fill the Email text field with : " + TestAccount.accountMail); AppiumTest.driver.findElement(By.name("email")).sendKeys(TestAccount.accountMail); log("Fill the Password text field with : " + TestAccount.facebookPassword); getFacebookPasswordTextField().sendKeys(TestAccount.facebookPassword); log("Tap on the Facebook WebView Log In button"); getFacebookWebviewLogInButton().click(); sleep(7); log("Accept the accessibilities by tapping on the OK button"); AppiumTest.driver.findElement(By.name("__CONFIRM__")).click(); AppiumTest.driver.context(String.valueOf(contextNames.toArray()[0])); new TouchAction((MobileDriver) getDriver()).tap(250, 367).perform(); // I try here to click on the button sleep(7);

Even if my tap action is before or after the changeContext, there is no action. Also, I’ve enabled the autoAcceptAlerts=true.

Do you have any suggest ?

It’s probably best to see what ARC and the Appium Inspector are giving you.
If you get into ARC, you can try finding things at page window:0 (1,2,3,4).

I’m not sure if this may help but
I have a problem with some custom alert view buttons where I cannot tap them by ID regardless of context.
Here’s what I did (This is iOS by the way, not sure offhand on Android - but I’m assume a similar solution exists)

#Summary:   After doing execute_script to list the tree, 
# found that the confirm button was the next to last button in the tree. 
# So I count back to that button and tap on it.
 @buttons_on_top_alert = "UIATarget.localTarget().frontMostApp().windows()[0].buttons()"
 number_of_buttons = execute_script(@buttons_on_top_alert).size
 submit_button_position=number_of_buttons-1
 submit_button_element=execute_script("#{@buttons_on_top_alert}[#{submit_button_position}]")
 submit_button_x_midpoint = submit_button_element.location.x+ (submit_button_element.size.width/2)
 submit_button_y_midpoint = submit_button_element.location.y+ (submit_button_element.size.height/2)
 action = Appium::TouchAction.new.tap(x: submit_button_x_midpoint, y: submit_button_y_midpoint)
 action.perform

Hope this proves helpful. Let me know if any questions.
Thanks!
Eric