Appium the context Switch

Source: Internet
Author: User

Original Address http://blog.csdn.net/Mandypan/article/details/51396302

Context Switch
Driver.getcontexthandles (); //Get the context of the page
Driver.context ("WEBVIEW");
Driver.context ("Nativeapp");


eg
public void Getresource_android () {
Set<string> Contextset=wd.getcontexthandles ();
for (String Context:contextset) {
SYSTEM.OUT.PRINTLN (context);
}

}

Context Switch
Driver.getcontexthandles ();
Driver.context ("WEBVIEW");
Driver.context ("Navtiveapp");


to view all current Windows:
Set<string> Contextnames=driver.getcontexthandles ();
System.out.print (Contextnames);
Switch to WebView
<pre name= "code" class= "Java" >driver.context ("WEBVIEW");
Driver.findelementbyid ("WD");
Switch to Nativeapp
<pre name= "code" class= "Java" >driver.context ("Native_app");


Demo
/**
* Switch to Native_app or WEBVIEW
* @param swindow window name
*/
private void Switchtowindow (String swindow) {
Logmanager.getlogger (This.getclass ()). info ("Swith to Window:" + Swindow);
set<string> contextnames = Driver.getcontexthandles ();
Logmanager.getlogger (This.getclass ()). info ("Exists windows:" + contextnames.tostring ());
for (String contextname:contextnames) {
if (Contextname.contains (Swindow)) {
Driver.context (Contextname);
Break
}
}
}

Switchtowindow ("WEBVIEW_com.test.android");
Switchtowindow ("Native_app");

Page switching

String Pwindurl = Driver.getcurrenturl (); gets the URL of the current window
Jump to a newly opened window
if (Driver.getwindowhandles (). Size ()! = 2) {fail ();}
For (String handle:driver.getWindowHandles ()) {
Driver.switchto (). window (handle); traverse jumps to each open window
if (driver. Getcurrenturl (). Equals (pwindurl) { If the URL of this window is Pwindurl it indicates that it is the current window
Driver.close (); //Close the current window
}

}

Appium the context Switch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.