In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "the element positioning of the common operation of Appium and the operation method of swipe slide screen". In the operation process of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First, open uiautomatorviewer
Use this tool to position everyone:
Implement a screenshot (usually used in this way, you can take a screenshot successfully).
Second, Appium common operation 1. What should I do if I report an error when I use layui to locate app elements?
It is recommended not to use layui. Layui has problems locating elements in some cases. When the environment is basically correct, it cannot take a screenshot. So you can abandon layui and use your own uiautomatorviewer (it supports all the positioning methods you have now).
two。 If you don't wait, will you report an error by looking for this element directly?
Like Web automation, it takes time for Appium to execute this command. This line of code goes into app, and app does one thing (a bunch of things) in the process, so even if you run only this line of code, it does a lot of things.
It feels like it takes longer than Web to wait, but it's faster than using a simulator if you're using a real machine.
So we need to wait before this. This WebDriverWait and EC conditional expression are used while Web automation is waiting. The same is true here, because the page waits for the element to appear and the element to be visible.
3. If it is Web automation, it will be import By. There are 8 ways to locate MobileBy in Appium. If you still use By, you can't use uiautomator and accessibility_id. So on the mobile side, the code:
From selenium.webdriver.common.by import By
To change it to:
From appium.webdriver.common.mobileby import MobileBy
No longer need to use By, By has id, class, it has. So, in this place, you have to wait for this id to appear, that is:
WebDriverWait (driver,20) .broadcast (EC.visibility_of_element_located ((MobileBy.ID,'com.huyu.yuncaidian:id/id_text')
This is the waiting work that must be done after opening app.
4. What if there is no such element on the welcome page?
If the default entry is the welcome interface, and you want us to slide left and right, then sleep, because you don't have a recognizable element.
It is useless to identify by the name of Activity, because it is also called Activity.
You can find it, but that doesn't mean it's out.
If there are clear elements, don't use time.sleep. Wait for the element to appear, and then manipulate the element.
This element is located in the same way as the Web element, in a variety of ways.
Android and ios have a limit on the size of their mobile screens, so there are not too many elements in a page and they are not very dense. Because it requires you not only to be able to see clearly but also to be able to light it with your hands. So it will do the pattern of the above content is less, the distance will be larger.
After clicking "my", the content of the page is switched. When you switch the content of the page, you have to wait, and it also needs to load time.
Open app and log in to # an app 2.9.0 quasi-environment
From appium import webdriver
Import time
From selenium.webdriver.support.wait import WebDriverWait
From selenium.webdriver.support import expected_conditions as EC
From appium.webdriver.common.mobileby import MobileBy
Desired_caps= {}
# platform type
Desired_caps ["platformName"] = "Android"
# platform version number
Desired_caps ["platformVersion"] = "7.0"
# device name
Desired_caps ["deviceName"] = "XPUDU17713003790"
# app package name
Desired_caps ["appPackage"] = "confidential"
# app entry acitivity
Desired_caps ["appActivity"] = "confidential"
# Connect to Appium server. Premise: appium desktop should be started. There is a listening port.
# send desired_caps to appium server. Open app
Driver = webdriver.Remote ('http://127.0.0.1:4723/wd/hub',desired_caps)
# before running the code:
# 1.appium server started successfully. Be in a monitoring state
# 2. The simulator / real machine must be recognized by the computer. That is, adb devices can recognize the device to be operated.
# Click "my"
Time.sleep (5)
# element positioning-combined positioning
Driver.find_element_by_xpath ("/ / * [@ resource-id='com.tfffc.cf:id/id_text' and @ text=' my']") .click ()
# Click on your phone password to log in
WebDriverWait (driver,20) .broadcast (EC.visibility_of_element_located ((MobileBy.ID,'com.tfffc.cf:id/tv_phone_passwad')
Driver.find_element_by_id ('com.tfffc.cf:id/tv_phone_passwad') .click ()
# enter the user name and password and click the login button
WebDriverWait (driver,20) .broadcast (EC.visibility_of_element_located ((MobileBy.ID,'com.tfffc.cf:id/editview_phone')
Driver.find_element_by_id ('com.tfffc.cf:id/editview_phone') .send_keys (' enter mobile phone number')
Driver.find_element_by_id ('com.tfffc.cf:id/editview_phone_password') .send_keys (' enter password')
Driver.find_element_by_id ('com.tfffc.cf:id/phone_password_login') .click ()
4. 1.swipe sliding screen operation unique to the mobile terminal.
Appium's swipe function slides against the coordinates on the screen. The swipe function is common to both Android and IOS devices.
If you slide from one point to another, each point has x and y values. Swipe has four parameters. So start x, start y, end x, end y.
two。 If you write an operation, all mobile phones can be applied, should you consider the size of the screen?
There are 5-inch, 4.4-inch and 5.7-inch mobile phones. The resolution is 1280x700, so its largest coordinate point is 1280x700. Different Android manufacturers, different sizes, its resolution is different, its coordinate values are absolutely different.
What about this? How to be compatible with this feature is better?
There is no need to write a code for each version of the phone, all common.
"there is a drawback in using coordinates: it may be suitable for a certain kind of mobile phone, but not for another phone, because the coordinate values do not match. "
3. Is there any way to get the size of the whole equipment?
Get its width and height directly. Slide against a coordinate point on the screen, not against an element. Sliding the whole screen means sliding left and right, sliding up and down.
Set the percentage of sliding down. If you slide 40%, 50%, it feels like you can't slide through at all. If you can get the size of the whole screen and slide as a percentage, the sliding distance is 70% Mur90%, then you can definitely slide past it.
According to the x-axis and y-axis of each phone, determine its sliding screen percentage, then any kind of phone can slide the screen. So when implementing this slippery screen, first get the size of the screen.
4. How to get the size of the screen? There is a special function:
Get_window_size returns the width and height of the window.
The return value of the function get_window_size ():
What is returned is a dictionary.
5. This thing wants to slide it over in one breath, but it can't slide halfway and go back. If I want to slide from right to left, how do I choose the starting point and the end point?
Swipe has two coordinate points, so the first step is to get start_x.
The x-axis is width. Size ['width'] is the maximum value for the x-axis.
"everyone's habit:" the slide screen is in the middle or slightly lower. The y-axis does not change when you slide from one page to another.
So the y value is fixed, so take an intermediate value of 0.5:#height and width
Size= driver.get_window_size ()
Start_x=size ['width'] * 0.9
Start_y=size ['height'] * 0.5
The sliding spacing had better be more than 80%. In this way, the spacing is 0.8: # height, width
Size= driver.get_window_size ()
Start_x=size ['width'] * 0.9
Start_y=size ['height'] * 0.5
End_x=size ["width"] * 0.1
Swipe also has a parameter called duration, which is in milliseconds.
6. How long are you going to take to slide?
After watching the operation of the mobile phone, if you slide too fast, it will have no effect at all. Sometimes it slides so fast that it ends before it can respond. So you can set duration (duration) to slow down a little bit, which is relatively more stable.
When you slide up and down, what is start_x?
Slide up and down, the x-axis remains the same, and the x-axis also takes the middle value. But the y-axis is getting smaller and smaller from the bottom up.
This can be encapsulated and called directly when needed in the future. Any device is the same. If some of the methods in webdriver indicate that it is only ios or Android, it can only be used on the corresponding platform.
If a function is not specified, then it is used by everyone, indistinguishable from each other.
# height 、 width
Size= driver.get_window_size ()
Start_x=size ['width'] * 0.9
Start_y=size ['height'] * 0.5
End_x=size ["width"] * 0.1
End_y=size ['height'] * 0.5
# slide from right to left
Driver.swipe (start_x,start_y,end_x,end_y,200)
# slide from left to right
Driver.swipe (end_x,end_y,start_x,start_y,200)
# Slide down
# Slide up: the x axis remains the same, y from large to small
Driver.swipe (size ["width"] * 0.5 heigth size ["heigth"] * 0.9 field size ["width"] * 0.5 field size ["heigth"] * 0.1)
# Slide upward: the x axis remains the same, y from small to large
Driver.swipe (size ["width"] * 0.5 width size ["heigth"] * 0.1 field size ["width"] * 0.5 field size ["heigth"] * 0.9) this is the end of the content of "element positioning of common Appium operations, what is the operation method of swipe slide screen". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.