I'm trying to automate an annoying login process. I'm hoping I can get a little help with it.
The app itself:
Launch app
App has a splash screen that can take various amounts of time to go away
Enter username, click submit
Next screen, checkboxes. Select phone then sms. Click submit
Wait for One Time Code, copy code and paste it in new screen. Click submit.
New screen, enter password, click submit.
Finally in the app.
________________
So far my script can...
Launch app
(Problem, if app isn't already running nothing else happens. It's that d@πn splash screen)
If app is running...
Username is entered correctly, submit is clicked
Next screen, checkboxes are successfully checked and submit clicked
(I haven't tried going any farther until I get the splash screen issue resolved. I'm pretty sure I can get the rest.)
I've been trying to set up a sort of if then loop where automagic will watch for that first submit button to show up before continuing. I've even tried having automagic wait ten seconds before continuing, I'd prefer the first solution, but even the second doesn't seem to work.
Any advice on this?
Seeking help automating app login
Moderator: Martin
Re: Seeking help automating app login
You can maybe try out something like this in the Control UI action:
It might not be ideal, but I found it reliable enough. So after you've done several actions and need to wait for the submit button to appear, as long as the button is not on screen, Automagic will be constantly running that loop. Of course, you need to get the id of the button using the Overlay Control that shows you the info of elements on screen. But then, once the button appears, add a little extra delay outside the loop and then click it.
You need to consider though, that with long waits + Control UI, the major issue would be that Automagic will trigger emergency stop, so if you made a mistake on your flow and can't turn it off, after a certain (quite large) amounts of actions made within a time space, it will stop it. It's a pretty good security measure but can lead to issues in this cases. So, there's a way to change it to a higher number depending on the flow or all the flows. As you're interested in a flow specific change, you can do this by going inside the flow, into the additional options with the three dots in the right top corner -> Options -> change Automagic emergency stop to specific, and set a high amount of actions that can be executed per minute until Automagic stops it. But first try if what I described works as it is, and then increase the emergency stop actions per minute executed to trigger if you experiment any issues.
Code: Select all
while(NOT existsElementById(id)) {
sleep(1);
}
You need to consider though, that with long waits + Control UI, the major issue would be that Automagic will trigger emergency stop, so if you made a mistake on your flow and can't turn it off, after a certain (quite large) amounts of actions made within a time space, it will stop it. It's a pretty good security measure but can lead to issues in this cases. So, there's a way to change it to a higher number depending on the flow or all the flows. As you're interested in a flow specific change, you can do this by going inside the flow, into the additional options with the three dots in the right top corner -> Options -> change Automagic emergency stop to specific, and set a high amount of actions that can be executed per minute until Automagic stops it. But first try if what I described works as it is, and then increase the emergency stop actions per minute executed to trigger if you experiment any issues.
-
- Posts: 179
- Joined: 16 Oct 2019 17:38
Re: Seeking help automating app login
@Amiller : You need to add sleep() enough to wait until the splashscreen loading finished. Just like ariloc's script above, you need to use sleep() in loop, waiting for the username field to appear. (find the element id using Control UI overlay). But don't use sleep(1), as it use too many CPU cycle and probably won't work properly. Use minimum 10 ms, or better, just 100 (you need to experiment with the latency). If you already wait for several seconds, additional 100ms should be not noticeable. This will save CPU cycle, as it only run 10 loop perseconds (instead of 100 loop if you use 10 ms).
Then you also need to put in some limiter, so your sleep() won't loop forever when error happen (example : you press home during splashscreen). I have explained the method here : viewtopic.php?f=5&t=7108
But now I have modified my code and make it in less lines, by compacting several logic into single lines. Example, my favourite element flow, waiting for the add... text, before proceeding.
Then you also need to put in some limiter, so your sleep() won't loop forever when error happen (example : you press home during splashscreen). I have explained the method here : viewtopic.php?f=5&t=7108
But now I have modified my code and make it in less lines, by compacting several logic into single lines. Example, my favourite element flow, waiting for the add... text, before proceeding.
Code: Select all
//waiting for timer
timer = 0;
while(getTextById("android:id/alertTitle") != "Add…" AND (timer = timer + 200) <= 3000)
sleep(200);
if(timer > 3000)
(msg = "Please add new element within 3 seconds!") / 0;
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
-
- Posts: 179
- Joined: 16 Oct 2019 17:38
Re: Seeking help automating app login
I usually use a sleep of 1 second, so didn't notice that was a 1ms which is heavy even for such a short wait.
Thanks.
P.S. I'd check if the app was still in the foreground to stop it if necessary.
Thanks.
P.S. I'd check if the app was still in the foreground to stop it if necessary.
Crude but it works.
Re: Seeking help automating app login
while(NOT existsElementById(id)) {
sleep(200);
}
This method just hangs until I stop the script.
//waiting for timer
timer = 0;
while(getTextById("id") != "Add…" AND (timer = timer + 200) <= 3000)
sleep(200);
if(timer > 3000)
(msg = "Please add new element within 3 seconds!") / 0;
This method hangs for a time, then gives an error
ch.gridvision.ppam.androidautomagis.simplelang.a.d: can not apply operation / to values 'Waiting' and '0' (Expression:msg = "Waiting") / 0(line 6)
Element ID's pulled from Control UI overlay
Here is what the UI Overlay is giving me for those peices...
value = existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_btnSubmit");
text = getTextById("ContentPlaceHolder1_MFALoginControl1_UserIDView_btnSubmit");
and
value = existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid");
text = getTextById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid");
My Code
while(NOT existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid")) { sleep(200); }
second attempt
while(getTextById("ContentPlaceHoloder1_MFALoginControl1_UserIDView_txtUserId") != "Add...;" AND
(timer = timer + 200 <= 10000)
sleep(200);
if(timer > 10000)
(msg = "Waiting") / 0;
On both of these, I'm looking at the user ID box while it is hung, or when I get the error message.
I've had a few times where the app takes 2 seconds to launch, others where it takes 20 seconds to launch. I'd like to get this working, but I must be doing something wrong.
Just spotted something weird.
while(NOT existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid")) { sleep(200); }
This hangs until I switch over to another app, then back. After that it enters the userID and clicks submit.
My brain hurts, what am I doing wrong?
sleep(200);
}
This method just hangs until I stop the script.
//waiting for timer
timer = 0;
while(getTextById("id") != "Add…" AND (timer = timer + 200) <= 3000)
sleep(200);
if(timer > 3000)
(msg = "Please add new element within 3 seconds!") / 0;
This method hangs for a time, then gives an error
ch.gridvision.ppam.androidautomagis.simplelang.a.d: can not apply operation / to values 'Waiting' and '0' (Expression:msg = "Waiting") / 0(line 6)
Element ID's pulled from Control UI overlay
Here is what the UI Overlay is giving me for those peices...
value = existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_btnSubmit");
text = getTextById("ContentPlaceHolder1_MFALoginControl1_UserIDView_btnSubmit");
and
value = existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid");
text = getTextById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid");
My Code
while(NOT existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid")) { sleep(200); }
second attempt
while(getTextById("ContentPlaceHoloder1_MFALoginControl1_UserIDView_txtUserId") != "Add...;" AND
(timer = timer + 200 <= 10000)
sleep(200);
if(timer > 10000)
(msg = "Waiting") / 0;
On both of these, I'm looking at the user ID box while it is hung, or when I get the error message.
I've had a few times where the app takes 2 seconds to launch, others where it takes 20 seconds to launch. I'd like to get this working, but I must be doing something wrong.
Just spotted something weird.
while(NOT existsElementById("ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid")) { sleep(200); }
This hangs until I switch over to another app, then back. After that it enters the userID and clicks submit.
My brain hurts, what am I doing wrong?
Re: Seeking help automating app login
Oh, sorry. Don't use my code here as it, it is to show my current improvement over my thread. You need to refer to my thread to find the element Id.
My script will wait for 3 seconds before creating error on purpose (dividing by zero will absolutely produce error). This is to protect from infinite loop.
You need much more time, so let's adjust to 20 seconds. "Add..." is for my flow, yours is different. You only need to check the existence of the element id, so use existElementById().
This should be working for you.
After the control UI, add another action : Notification on Screen, put {msg} in the box. Then tap the connector between Control UI and the Notification on Screen, tap the pencil icon (edit) and change the connection to Exception. This Notification on Screen will be executed only when the timeout reach and error is produced. So you don't get the Automagic error ....
If the app frequently hang and only show the UI after switch to recent and back, you can probably use Control UI to tap recent, wait for a while. Then tap the app again. This should trigger the switch and maybe can load the app faster.
My script will wait for 3 seconds before creating error on purpose (dividing by zero will absolutely produce error). This is to protect from infinite loop.
You need much more time, so let's adjust to 20 seconds. "Add..." is for my flow, yours is different. You only need to check the existence of the element id, so use existElementById().
This should be working for you.
Code: Select all
//declare element id
id = "ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid";
//waiting for timer
timer = 0;
while(!existsElementById(id) AND (timer = timer + 200) <= 20000)
sleep(200);
if(timer > 20000)
(msg = "Please add new element within 3 seconds!") / 0;
If the app frequently hang and only show the UI after switch to recent and back, you can probably use Control UI to tap recent, wait for a while. Then tap the app again. This should trigger the switch and maybe can load the app faster.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.