当前位置:网站首页>Auto. JS learning notes 8: some common and important APIs
Auto. JS learning notes 8: some common and important APIs
2022-06-12 09:54:00 【PYB3】
Catalog
scrollForward(): Slide your fingers up
scrollBackward(): Slide your fingers down
setInterval(callback, delay[, ...args])
UiSelector
UiSelector The selector , Used to select controls on the screen by various conditions , Then click on these controls 、 Long press and other actions . Here we need to briefly introduce the relevant knowledge of controls and interfaces
text(str)
str{string} Control text- return {UiSelector} Returns the selector itself to chain call
Attach controls to the current selector "text Equal to string str" The screening criteria for .
The control of text( Text ) Property is the text displayed on the text control , For example, in the upper left corner of wechat " WeChat " Text .
findOne()
- According to the filter criteria determined by the current selector , Search for controls on the screen , Until a control that meets the conditions appears on the screen , And return the control . If the control is not found , When the content of the screen changes, it will look again , Until you find .
- It should be noted that , If the described control does not appear on the screen , Then the function will block , Until the described control appears . So this function does not return
null. - Adopt depth-first search (DFS), The first control found by the search algorithm will be returned . Note that the order in which controls are found sometimes works .
findOnce(i)
i {number} Indexes
According to the filter criteria determined by the current selector , Search for controls on the screen , And return to i + 1 Controls that meet the criteria ; If no matching control is found , Or the number of qualified controls < i, Then return to null.
Note the order of the controls here , Is the search algorithm depth first search (DSF) Decisive .
findOne(timeout)
timeout{number} Search timeout , Unit millisecond- return UiObject
- According to the filter criteria determined by the current selector , Search for controls on the screen , Until a control that meets the conditions appears on the screen , And return the control ; If in timeout No eligible controls were found within milliseconds , Terminate the search and return
null. - This function is similar to the
findOne(), It's just a time limit .
Example :
// start-up Auto.js
launchApp("Auto.js");
// stay 6 Seconds to find the log icon
var w = id("action_log").findOne(6000);
// If the control is found, click
if(w != null){
w.click();
}else{
// Otherwise, the prompt is not found
toast(" No log icons found ");
}findOnce()
- return UiObject
- According to the filter criteria determined by the current selector , Search for controls on the screen , If a matching control is found, the control is returned ; Otherwise return to
null.
find()
- return UiCollection
- According to the filter criteria determined by the current selector , Search for controls on the screen , Find all the control collections that meet the criteria and return . This search is done only once , There is no guarantee that you will find , Therefore, the returned control collection will be empty .
- differ
findOne()perhapsfindOnce()Only one control is found and one control is returned ,find()Function will find all the controls that meet the conditions and return a collection of controls . After that, you can operate on the control collection .
scrollable([b = true])
- b {Boolean} Indicates whether the control is slidable
Attach a condition for whether the control is slidable for the current selector . Sliding includes up and down sliding and left and right sliding .
You can use this condition to find a sliding control to slide the interface . For example, sliding Auto.js The code of the script list of is :
className("android.support.v7.widget.RecyclerView").scrollable().findOne().scrollForward();
// perhaps classNameEndsWith("RecyclerView").scrollable().findOne().scrollForward();bounds()
- return Rect
- Returns the range of the control on the screen , Its value is a Rect object .
Example :
var b = text("Auto.js").findOne().bounds();
toast(" The scope of the control on the screen is " + b);- If a control itself cannot pass
click()Click on , Then we can usebounds()Function to get its coordinates , Then click with the coordinates . for example :
var b = desc(" Open the side pull menu ").findOne().bounds();
click(b.centerX(), b.centerY());
// If you use root jurisdiction , Then use Tap(b.centerX(), b.centerY());auto.setMode(mode)
mode{string} Pattern
Set the accessibility mode to mode.mode The optional values of are :
fastFast mode . Control caching is enabled in this mode , This makes it faster for selectors to get screen controls . This mode can be used for scripts that require quick control viewing and operation , General scripts do not need to use this function .normalNormal mode , Default .
auto.waitFor()
Check whether the accessibility service is enabled , If it is not enabled, you will jump to the barrier free service enabling interface , And wait for the accessibility service to start ; When the accessibility service is started, the script will continue to run .
auto.setMode(mode)
mode{string} Pattern
Set the accessibility mode to mode.mode The optional values of are :
fastFast mode . Control caching is enabled in this mode , This makes it faster for selectors to get screen controls . This mode can be used for scripts that require quick control viewing and operation , General scripts do not need to use this function .normalNormal mode , Default .
click(text[, i])
text{string} Text to click oni{number} If the same text appears more than once on the screen , be i Indicates which text to click , i from 0 Start calculating- Returns whether the click was successful . When the screen does not contain this text , Or return when the area where the text is located cannot be clicked false, Otherwise return to true.
Usage mode :
click(" Yes ") : When no parameter is specified i Will try to click on all the text that appears on the screen text And return whether all clicks are successful .
click(" Yes ",0) : It's from 0 Start calculated , Means to click the first... On the screen " Yes ".
UiObject
UiObject Represents a control , You can get the properties of the control through this object , You can also click on the control 、 Long press and so on .
Get one UiObject Usually through the selector findOne(), findOnce() Such as function , It can also be done through UiCollection To get , Or by UiObject.child(), UiObject.parent() And other functions to get the child control or parent control of a control .
text()
- return {string}
- Gets the text of the control , If the control has no text , return
"".
scrollForward(): Slide your fingers up
- return {Boolean}
- Slide the control forward , And return whether the operation was successful .
- Sliding forward includes sliding right and down . If a control can slide both right and down , Then perform scrollForward() The behavior of is unknown ( This is because Android The documentation does not point this out , At the same time, there are not enough tests for reference ).
scrollBackward(): Slide your fingers down
- return {Boolean}
- Slide the control backward , And return whether the operation was successful .
- Sliding backward includes sliding right and down . If a control can slide both right and down , Then perform scrollForward() The behavior of is unknown ( This is because Android The documentation does not point this out , At the same time, there are not enough tests for reference ).
timers Timer
timers The module exposes a global API, Used to call the scheduling function in a future time period . Because the timer function is global , So use this API Don't need to call timers.*
setTimeout
setTimeout(function(){
toast("hello")
}, 5000);matters needing attention
It should be noted that , These timers are still single threaded . If the script body There are time-consuming operations or dead cycles , Set timer Cannot be executed in time
setTimeout(function(){
// The statement here will be in 15 Execute in seconds instead of 5 Seconds later
toast("hello")
}, 5000);
// Pause 10 second
sleep(10000);Dead cycle
setTimeout(function(){
// The statement here will never be executed
toast("hello")
}, 5000);
// Dead cycle
while(true);setInterval(callback, delay[, ...args])
callback{Function} The function to be called when the timer reaches the point .delay{number} call callback The number of milliseconds to wait before ....args{any} When calling callback Optional parameters to be passed in .
var i = 0;
setInterval(function(){
i++;
toast(i + " second ");
if(i == 19999){
back();
sleep(1000)
log(" Send successfully !1");
exit();
}
}, 3000);clearTimeout(id)
id{number} One setTimeout() Back to id.
Cancel a by setTimeout() Created scheduled tasks .
// Every time 5 Every second hello
var id = setInterval(function(){
toast("hello");
}, 5000);
//1 Minutes later, cancel the cycle
setTimeout(function(){
clearInterval(id);
}, 60 * 1000);边栏推荐
猜你喜欢

Transport layer protocol -- TCP protocol

True north reading notes

UE4_以现成资源探索创建背景场景的方法

SAP HANA 错误消息 SYS_XSA authentication failed SQLSTATE - 28000

【clickhouse专栏】基础数据类型说明

卖疯了的临期产品:超低价、大混战与新希望

Autojs微信研究:微信不同的版本或模拟器上的微信里的控件ip是不同的。

Network layer IP protocol ARP & ICMP & IGMP nat

行业分析怎么做

Explanation of the principle of MySQL's leftmost matching principle
随机推荐
Differences among list, set and map
简单介绍线程和进程区别
UEFI EDKII 编程学习
002: what are the characteristics of the data lake
《保护我们的数字遗产:DNA数据存储》白皮书发布
[path of system analyst] Chapter 18 security analysis and design of double disk system
Auto.js学习笔记8:常用且重要的一些API
Network layer IP protocol ARP & ICMP & IGMP nat
Clickhouse column basic data type description
2022 极术通讯-安谋科技纷争尘埃落定,本土半导体产业基石更稳
存储研发工程师招聘
在线电路仿真以及开源电子硬件设计介绍
2026年中国软件定义存储市场容量将接近45.1亿美元
Pandorabox uses firewall rules to define non internet time
《第五项修炼》读书笔记
总有一根阴线(上影线)会阻止多军前进的脚步,总有一个阳线(下影线)会阻挡空军肆虐的轰炸
List of computer startup shortcut keys
Record and store user video playback history selection
C#入门系列(十二) -- 字符串
7-5 哲哲打游戏