How to wait for tab with title containing string?

Hi all,

I’m dealing with this: I click a button that opens a new tab, takes some seconds to load and when it loads I need to click in a button that is behind 2 iframes, But in order to use “SelectFrame | index=0”, I need to be sure that the page is already loaded.

Is there a way to do something like waitForElementPresent | title = "*some string*?

Here is what ChatGPT told me, and it sounds correct:

To wait for a change in the title text using UI.Vision RPA, you would typically use a combination of commands in a loop to periodically check for the title until it matches your desired condition. Since UI.Vision RPA does not have a direct command like waitForElementPresent specifically for page titles, you’d need to implement a custom loop that checks the title at intervals. Here’s a conceptual approach:

  1. Store the Initial Title: Use the storeTitle command to save the current page title in a variable.
  2. Loop Until the Title Changes: Implement a loop using the while | !${done} structure. Within this loop, you will:
  • Use storeTitle again to check the current title and store it in another variable.
  • Use the if command to compare the new title variable to your expected title or to check if it contains a specific string.
  • If the title matches your criteria, set a variable (e.g., ${done}) to true to break the loop.
  • If the title does not match, use pause to wait for a short period before checking again.
  1. Proceed Once the Title Matches: After the loop exits, you can proceed with your actions, such as interacting with elements inside the iframes.

Here is a simplified version of the script steps you might use:

store | false | done
label | startLoop
storeTitle | currentTitle
if | "${currentTitle}" == "YourExpectedTitleHere" | |
store | true | done
endIf
if | "${done}" == "false" | |
pause | 1000 // Wait for 1 second before checking the title again
gotoLabel | startLoop
endIf
// Your next actions go here, after the title has changed to the expected value.

This script checks for a title exactly matching “YourExpectedTitleHere”. If you’re looking for a title that contains a certain string (e.g., part of the title), you’d modify the condition in the if command accordingly.

Please adjust the intervals and conditions based on your specific needs and the behavior of the website you’re automating.

Thanks ulrich for your answer. It works!

I was wondering if store | true/false | variable works for you? since

If I do store | false | variable, I get error
command[field].trim is not a function

and if I do store | true | variable, I get error
command.target.trim is not a function

Additionally, I’ve tried to check if title contains a string using “title.includes()…” and fails. It worked for me using LastIndexOf like in this post

store | true | test works for me:

    {
      "Command": "store",
      "Target": "true",
      "Value": "test",
      "Description": ""
    },

Can you post a test macro with the error?

Correct. That is because executeScript_SANDBOX supports only ES5 Javascript, not the newer ES6.

I mean store in variable “test” the boolean true/false not the string “true”. In your example ${test} = “true”

This is a sample macro.

{
  "Name": "test_store_true",
  "CreationDate": "2024-4-7",
  "Commands": [
    {
      "Command": "store",
      "Target": true,
      "Value": "test",
      "Description": ""
    },
    {
      "Command": "if",
      "Target": "( ${test} === true )",
      "Value": "test",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${test}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}