Created
April 23, 2018 15:21
-
-
Save sauceaaron/01af226f71aa638201819ec5aa84a292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.appium.java_client.AppiumDriver; | |
| import java.util.Set; | |
| public class SwitchToWebView | |
| { | |
| public void switchToWebContext(AppiumDriver driver) | |
| { | |
| String webContext = getWebContext(driver); | |
| System.out.println("got web context: " + webContext); | |
| if (driver.getContext().equals(webContext)) | |
| { | |
| System.out.println("already in web context"); | |
| return; | |
| } | |
| driver.context(webContext); | |
| } | |
| public String getWebContext(AppiumDriver driver) | |
| { | |
| Set<String> contextHandles = driver.getContextHandles(); | |
| for (String contextHandle : contextHandles) | |
| { | |
| System.out.println(contextHandle); | |
| if (contextHandle.contains("WEBVIEW")) | |
| { | |
| return contextHandle; | |
| } | |
| } | |
| throw new RuntimeException("No webview context found"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment