Page 1 of 1
Regex expression
Posted: 03 Dec 2018 11:02
by robchoc
I'm trying to write a script that will automate this number captcha but I'm stuck with the Regex expression that I need to use.
I need to get the first number into my first variable and the second number into my second variable.
Debug dialog show this:
press 24, 32 (can also be single numbers like 3, 22 or 3, 5 or 12, 4)
1
2
3
4
5
and so on...
The rest seems fairly simple as I would put the first number into no1 variable and the second into no2.
I would then click no1 and then no2.
Thanks
Re: Regex expression
Posted: 03 Dec 2018 12:11
by anuraag
I dont understand what you want?
You need regex for "press 24,32"?
Or you want Variable1=24 and Variable2=32
Re: Regex expression
Posted: 03 Dec 2018 12:31
by robchoc
What I'm trying to do is get the first number into Variable1 and the second number into Variable 2
Possible combinations of numbers are:
press ?, ?
press ?, ??
press ??, ?
press ??, ??
I need the regex expression to get the numbers. Or maybe there is another way.
This is an example of the debug string that I have to work with:
press 24, 32
1
2
3
4
and so on upto 36
So if you had to get the numbers into 2 different variables, how would you do it?
Re: Regex expression
Posted: 03 Dec 2018 12:58
by anuraag
So you need to first grab press ??, ?? from your string. If i am not wrong it looks like
Code: Select all
press + space + number + comma + space + number
Your string looks like
press 24, 32
1
2
3
4
So this will give you press ??, ??
Code: Select all
output=findAll("string", 'press\\s\\d+,\\s\\d+')
Then
var[0] will give first number
var[1] will give second number
Re: Regex expression
Posted: 03 Dec 2018 16:02
by robchoc
Got it working, many thanks.
Re: Regex expression
Posted: 03 Dec 2018 16:51
by robchoc
I have another issue and that is when my screen does not show the captcha.
The screen with the captcha pops up occasionally and I only want my script to run when it does otherwise it throws up an error invalid index 0.
I have the following in my script:
Code: Select all
**
**
**
text=getTextInActiveWindow();
sleep (2000);
output=findAll({text}, 'press\\s\\d+,\\s\\d+');
var=findAll(output, '\\d+');
click(var[0]);
sleep (500);
click(var[1]);
**
**
**
It's fine when I have the captcha but when it does not have one it stops working.
What is the best way to only run this part of the script if the captcha pops up?
Thanks.
Re: Regex expression
Posted: 03 Dec 2018 17:06
by anuraag
Use condition while or if
While will loop untill that dialogue appears.
If will check only once
Code: Select all
while (!existsElementById("android:id/button1"))
{sleep(100)
}
Your script
Code: Select all
if (existsElementById("android:id/button1"))
{your script
}
You need to find element id by using overlay control helper.
Re: Regex expression
Posted: 03 Dec 2018 17:14
by anuraag
You can also replace existsElementById with other like getText or getTextById.
Edit : here @Desmanto shown how to use condition.
http://automagic4android.com/forum/view ... 825#p22825
Re: Regex expression
Posted: 03 Dec 2018 17:32
by robchoc
Perfect I went for the if with {}
Many thanks