5 minutes to quickly learn App automation test xpath positioning (recommended collection)

Today, let’s talk about appium first, and first teach you how to locate xpath, and you can learn it in five minutes:
Example:
Now I want to locate the following login button:

How should xpath be written?

Regardless of the three or seven or twenty, first write //, and then find the closest element you want to locate that can be directly located. We see that homethe attribute is content-desc:

So we can directly locate the red home in the above picture according to the content-desc attribute. These attributes are all under this WebView, so continue:

//adnroid.webkit.WebView[@content-desc='home']/

Next is a View, and then the second View below him is what we want to locate

//android.webkit.WebView[@content-desc='home']/android.view.View/android.view.View[2]
If you exchange experience in software testing, interface testing, automated testing, and interviews. If you are interested, you can add software testing communication: 1085991341, and there will be technical exchanges with colleagues.
In this way, you can locate it. There are two explanations.

First: The index of xpath starts from 1, not from 0;

Second: see the beginning of View, you can’t write View directly in xpath, you have to write android.view.View

As far as the above two points need to be noted, do you know it now? Another example:

In the positioning box:

Write // first, then look at the home line, and know to write like this:

//android.webkit.WebView[@content-desc='home']

Then see that the positioned View is in the ListView, and continue to write:

//android.webkit.WebView[@content-desc='home']/android.widget.ListView/android.view.View[3]

Don’t just look at it, write it yourself and try it out. I’ll give you the ready-made code. You can copy it and change the corresponding parameters to use it:

# coding: utf-8from appium import webdriverfrom time import sleep

desired_caps = {'platformName': 'Android',                'deviceName': '',                'platformVersion': '6.0',                'appPackage': '',                'appActivity': '',                'unicodeKeyboard': True,                'resetKeyboard': True}                
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

sleep(3)# 点击登录driver.find_element_by_xpath("").click()                

I hope the above content is helpful to you. Friends who have been helped are welcome to like and comment. 

END meager strength

Finally, I would like to thank everyone who has read my article carefully. Looking at the fans’ growth and attention all the way, there is always a need for reciprocity. Although it is not a very valuable thing, you can take it away if you need it:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you too!

加入我的软件测试交流群:110685036免费获取~(同行大佬一起学术交流,每晚都有大佬直播分享技术知识点)

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

method of obtaining:

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/130684119