Dynamic delay in Web Automation

Hi Team

How do we wait for specific element/Tag/Selector to appear before proceeding to next step during a web automation ? I was able to see few dynamic delays in documentation but in case of web automation is there something I am missing ?

To make your script for web automation more dynamic you could create checks that contain the following actions:

  • WebAutomation.WebPageContainsElement BrowserInstance: Control:
  • WebAutomation.WebPageContainsText BrowserInstance: Text:

For example, you could implement an if statement that utilizes these actions and branches accordingly (maybe set a delay and then repeat the check?).

Hope it helps.

Best regards,
J.

Yes WebAutomation.WebPageContainsElement BrowserInstance: Control: will have to be be checked in loop along with wait if I want to wait for element to load.
But I was looking for more direct way like below. Additional argument could be for how long to wait for this element to exist.

WebAutomation.WebPageContainsElement BrowserInstance: Control: Wait:

Thanks

1 Like

The syntax should be like this:
image

Think that the WebContainsElement action returns a true/false output that in turn is utilized inside an if statement.
Regarding the wait interval, I am afraid that this is not a static answer.
It depends of a variety of conditions and it definitely is something that should be decided by whoever develops the script.

Best regards,
J.

1 Like

So…follow up question…related to this If I want to check for the text would it be something like this? I am getting an error still when I check the script that Browser is not a variable.

set Google to “https://www.google.com
WebAutomation.LaunchInternetExplorer Url: Google WindowState:WebAutomation.BrowserWindowState.Normal ClearCache:False ClearCookies:False CustomUserAgentString:’’ BrowserInstance=> Browser

wait 1
label check_for_text
If (WebAutomation.WebPageContainsText BrowserInstance: Browswer Text: Google) then
WebAutomation.CloseWebBrowser BrowserInstance: Browser
else
wait 5
goto check_for_text
end

I rewrote this to use Chrome and it worked fine…not sure why it had an error.

set Google to “https://www.google.com
WebAutomation.LaunchChrome Url: Google WindowState:WebAutomation.BrowserWindowState.Normal ClearCache:False ClearCookies:False BrowserInstance=> Chrome
wait 1

label check_for_text
If (WebAutomation.WebPageContainsText BrowserInstance: Chrome Text: Google) then
WebAutomation.CloseWebBrowser BrowserInstance: Chrome
else
wait 5
goto check_for_text
end

Hello @rgreig01 and welcome to our community!

You must first capture an element using UI Spy.
After that you must get the inner text of the control inside the WebContainsText action.

Since you don’t provide a custom selector (captured element), the action doesn’t know where to search.
This applies for both browsers.
You also have a typo in your first script, inside the if condition ( you have Browswer instead of Browser).

Hope this helps.

Best regards,
J.

1 Like

I would like to go ahead with something like this to avoid infinite loop in case element does not appear.

function waitForObject Instance,Object
   set cnt to 1
    
    loop while(cnt<10)
        if (WebAutomation.WebPageContainsElement BrowserInstance:Instance  Control:Object) then
                           exit loop
        else
            wait 1
            set cnt to cnt+1
        end 
    end
end
2 Likes

Very nice logic @Sahil!
As we have constantly stated, scripts should be
easy to read and created in a way that allows for convenient maintenance and secure execution.

Best regards,
J.

1 Like