How to automate this: Refresh the page continuously in 5sec interval until a element is visible in the web

Hey,
I have an element that becomes enabled at different intervals, sometimes after 60 seconds, and other times after 20 seconds, etc. However, I want to keep clicking on that element until it becomes visible. If the element does not become visible, the page should refresh. Once the element is visible, I want to click on it.

Please suggest how to do that. Thanks in advance.

I would use visualAssert + Repeat/If - For more details please see

{
  "Command": "do",
  "Target": "aria-label=\"STATUS\"",
  "Value": "/-- RELOAD PAGE TILL CONTENT SHOWN --\\",
  "Description": ""
},

{
“Command”: “refresh”,
“Target”: “”,
“Value”: “-> REFRESH PAGE”,
“Description”: “”
},
{
“Command”: “pause”,
“Target”: “3000”,
“Value”: “-> WAIT AND TO SEE IF PAGE LOADED”,
“Description”: “”
},
{
“Command”: “sourceSearch”,
“Target”: “aria-label="STATUS"”,
“Value”: “myNbrPageLoaded”,
“Description”: “If no ‘STATUS’ shown, page is not completely loaded”
},
{
“Command”: “repeatIf”,
“Target”: “(${myNbrPageLoaded} == 0)”,
“Value”: “\– RELOAD PAGE TILL CONTENT SHOWN --/”,
“Description”: “-> No STATUS visible on page otherwise it will show 4x STATUS if page loaded”
},

Hello @noahhath , thank you for your response. I am new to UiVision, and your provided solution is a bit challenging to comprehend.

I am navigating a page that contains the xpath= //b[contains(text(),‘Data export reports’)], is used for navigation, and the subsequent XPath I need to click on is //tbody/tr[1]/td[3]/a[1]. However, this button’s visibility is not immediate; it appears after some time. Initially, the status displays ‘Export is in progress,’ and then it changes to ‘Download export,’ making the element with XPath //tbody/tr[1]/td[3]/a[1] (this the element I want to click) accessible. The waiting time for this button varies; sometimes, it takes 5 seconds, while other times, it takes over 60 seconds to become visible. So I want to refresh the page until the ‘Export is in progress’ changed to ‘Download export’ and then I want to click on ‘Download export’ button. Could you please provide me with the JSON code based on this scenario? Thank you!

Hi @noahhath ,

This is what I have made. please check weather this is correct or not.

{
“Command”: “do”,
“Target”: “//tbody/tr[1]/td[3]/a[1]”,
“Value”: “”,
“Description”: “Reload the page till DownloadExportButton is not visible”
},
{
“Command”: “refresh”,
“Target”: “”,
“Value”: “”,
“Description”: “If not Visible then refresh the page”
},
{
“Command”: “pause”,
“Target”: “3000”,
“Value”: “”,
“Description”: “Pause for 3sec”
},
{
“Command”: “sourceSearch”,
“Target”: “//tbody/tr[1]/td[3]/a[1]”,
“Value”: “DownloadExportButton”,
“Description”: “”
},
{
“Command”: “repeatIf”,
“Target”: “(${DownloadExportButton} == 0)”,
“Value”: “”,
“Description”: “Reload the page till DownloadExportButton is not visible”
},
{
“Command”: “click”,
“Target”: “//tbody/tr[1]/td[3]/a[1]”,
“Value”: “”,
“Description”: “Click on Download report button and wait for 5sec.”
}

Hi,

I have in general a hard time to read through other people’s source code but I do believe you are on the right path. :slight_smile:
Here is my code in a different view that might make it easier to understand.
In my case I do not refresh the page but load it once and wait for a “status” to show up.
I check on this every 3 seconds.

You you feel you need to refresh the page every 5 seconds you can place a the “refresh” command into your repeatIf loop.

Note: I use sourceSearch instead of “waitTillElementVisible” to prevent an error log to be created on timeout. (timeouts usually stops script, which can be prevented, but will still create an error log.)

Hi @noahhath thank you for your response. This is happening as expected but the loop is still continuing even after the element is visible on the web page.

1 Like