Chrome Debug mode Get App Mix app H5 interface elements

Source: Internet
Author: User

Original article Address http://blog.csdn.net/qq_19636353/article/details/53731254

The remote debugging tool of the browser allows us to debug the running code in the phone's browser via the console that is open on the PC. Chrome for Android running on Android 4+ system can also be used with ADB (Android debug Bridge) for Remote Desktop debugging. The desktop version of chrome32+ already supports the remote debugging of mobile device page/webview by installing ADB-free.

Android remote debugging currently supports all operating systems and supports the following:
To debug a site's page
Debug WebView in Android native app
Display the Android device's screen image in real time to the development machine.
Enable interactive debugging of Android mobile devices and development servers via port forwarding and virtual host mapping (Vsan mapping).

In the latest version of Android 4.4 KitKat, the WebView implementation based on Android WebKit was replaced by chromium-based WebView implementations.

Mobile side
1. Configuring the ANDROIDSDK Environment in Eclipse (Android6.0, ADT23.0)
2. Connect the phone with the PC via USB and turn on the USB debug mode;
3. Use the 360 phone assistant or enter ADB devices in the DOS window to see if the phone driver connection is successful;

PC-Side
1. Enter Chrome://inspect in the Chrome browser address bar to enter debug mode;
2. This page shows the phone model, driver name, app to debug the WebView name;
3. Click Inspect to successfully load the debug page with the same interface as the app side, then the configuration is successful;
4. If you do not get WebView or the Debug Page preview box appears blank, you need to do VPN cracking – install FQ software (because the default Devtools uses Appspot server, which is required to climb GWF in China)

Chromedriver

Appium通过 chromedriver-port 9515进行通信,驱动安卓手机上的WebView;查看手机系统应用Android System WebView显示的Chrome版本,下载对应的chromedriver并添加到Appium的chromedriver目录,保证驱动程序版本对应,Appium后台启动时会自动重启chromedriver,此时后台不会出现等待chromedriver启动现象;
    • 1
    • 2
    • 3
    • 4
//杀掉chromedriver进程并重启,要先切换到NATIVE_APP(包括端)public static void RestartChromedriver() throws Exception{ Runtime.getRuntime().exec("taskkill /F /im chromedriver.exe"); System.setProperty("webdriver.chrome.driver", "D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe");}
    • 1
    • 2
    • 3
    • 4
    • 5
端口被占用解决方案:http://jingyan.baidu.com/article/a501d80c26cd90ec620f5e5e.html
    • 1
    • 2

Appium switch context, toggle WebView

Import Java.util.Set;Import Java.util.concurrent.TimeUnit;Import org.openqa.selenium.WebElement;Import Com.tms.app.itms.logs.Log;Import Io.appium.java_client.android.AndroidDriver;PublicClassitms_getelement{PublicStaticvoidGetcontexthandle (androiddriver<webelement> driver) {set<string> context =null;Forint i=1;i<=20;i++) {context = Driver.getcontexthandles ();for (String contextname:context) {System.out.println (contextname);Print the current contextif (contextname!=Null && contextname.contains ("WEBVIEW_COM.QUANTUM.TMSP7") | | Contextname.contains ("WEBVIEW_com.tencent.mm:tools")) {Switchto_webview (driver); Driver.getpagesource ();Return }if (i==20)AssertFalse } log.gosleep (1); } }PublicStaticvoidSwitchto_webview (androiddriver<webelement> driver) {String str = driver.currentactivity ();Check the current appForint k=0;k<30;k++) {try {if (str.equals (return;} else if (str.equals (return;} } catch (Exception e) {if (K<10) {Log.info (if (K==30) {log.fatal (Driver,  " Switch fail! ", e); }} finally{driver.manage () timeouts (). implicitlywait (1, Timeunit.seconds); } } }} 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21st
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

Test script (Inherit selenium)

Loginsubmititms_getelement. Getcontexthandle (Driver);d River. Findelementbyid ("username"). SendKeys ("15029200344");d river.findelementbyid ( " Password ") .sendkeys (" 111111 ") ;d river.findelementbycssselector (  "#loginSubmit") .click () ;//switchto_native get current Location-check [Allow] button itms_ Getelement.getalerttitlenewthread (driver) ;//millet, Huawei Thread.sleep (3000) ;ITMS _getelement.switchto_webview (driver) ;d River.quit ()         
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

Other

    • 1
    • 2
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT) {       WebView.setWebContentsDebuggingEnabled(true);}
    • 1
    • 2
    • 3
由于大部分App的debug模式是关闭的,即便是内部App,比如QQ/,要去找一个开启了debug模式的版本还是比较麻烦的。因此需要使用借助第三方工具来强制开启任何App的Android webview debug模式,使之可以使用 chrome inspect。
    • 1
    • 2

Collect URLs

Chrome remote Debugging for mobile Web development Debugging (remotes debugging)
http://blog.csdn.net/freshlover/article/details/42528643

Automation Technology of Appium WebView
https://testerhome.com/topics/6954

HTML5, WebKit, Chromium
Http://blog.csdn.net/milado_nju
Understand WebKit and Chromium:webkit, WebKit2, chromium and chrome introduction
http://blog.csdn.net/milado_nju/article/details/7292164

How to build WebView in Android app
http://blog.csdn.net/tangcheng_ok/article/details/6951113

Eight common ways to locate Selenium webdriver elements
Http://www.cnblogs.com/qingchunjun/p/4208159.html
How to choose the positioning method:
1. When the page element has an id attribute, it is best to use ID to locate it. However, because many programmers in the real project actually write code that is not canonical, and will lack many standard attributes, then only choose other location method.
2. XPath is strong, but the positioning performance is not very good, so try to use less. If you do not have a few elements that are not well positioned, you can choose XPath or cssselector.
3. Consider using tagname or name when you want to locate the same element for a group of elements.
4. When a link needs to be located, consider Linktext or Partiallinktext mode.

Chrome Debug mode Get App Mix app H5 interface elements

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.