- Joined
- Feb 23, 2018
- Messages
- 225
- Reaction score
- 35
- Achievement
Hi, In this tutorial, I will show you how to click to an element within a condition, such as I want to click to a skip-button only when it's ready !
If you are new with 9Hits Macros, I recommened to read the basic tutorial here!
Let take a look on an example link from adfly: http://adf.ly/1Qt15t
Please pay attention on the different when the skip-button (skip_bu2tton) is hidden and when it's shown. As you can see, when the button is hidden (the timer still counting), It's has attribute display = "none". And when it's shown, the display="none" was gone.
When it's hidden
When it's shown
Ofc you can find any other different things from the button or event from other element (for exmaple, you may check for the timer. timer counting => still hide, timer stopped => skip button is show). I just want to use the display thing.
So I would like to implement my idea like this
1. Wait for page loaded
2. Check for the display of the skip-button when it's display attribute NOT is "none"
3. Click to the skip-button !
The script should be
Let testing the script with macro editor
https://youtu.be/fOEQDmiaM6M
You can now click to skip-button without worry about Delay . For the others, it's the same theory to make macros !
If you need any help, just leave me a comment
Regards!
If you are new with 9Hits Macros, I recommened to read the basic tutorial here!
Let take a look on an example link from adfly: http://adf.ly/1Qt15t
Please pay attention on the different when the skip-button (skip_bu2tton) is hidden and when it's shown. As you can see, when the button is hidden (the timer still counting), It's has attribute display = "none". And when it's shown, the display="none" was gone.
When it's hidden
When it's shown
Ofc you can find any other different things from the button or event from other element (for exmaple, you may check for the timer. timer counting => still hide, timer stopped => skip button is show). I just want to use the display thing.
So I would like to implement my idea like this
1. Wait for page loaded
2. Check for the display of the skip-button when it's display attribute NOT is "none"
3. Click to the skip-button !
The script should be
Code:
await Delay(1000);
//while browser is still loading, delay for 1s and continue to check
while(await IsLoading())
{
await Delay(1000);
}
//while the display of the skip_bu2tton still = none, delay for 1s and continue checking
while(await EvaluateScript("skip_bu2tton.style.display") == "none")
{
await Delay(1000);
}
//If the macros can go here, it's mean the site has been loaded
//and the skip button has been shown
Alert("Skip button is ready !"); //just for test, should be remove in real works
ClickById("skip_bu2tton");
https://youtu.be/fOEQDmiaM6M
You can now click to skip-button without worry about Delay . For the others, it's the same theory to make macros !
If you need any help, just leave me a comment
Regards!