Forum Discussion

tvklovesu's avatar
tvklovesu
Frequent Contributor
3 years ago

Getting error when checking for object not Exists or Visible

Hi friends,

I got stuck with this issue for last two days and really scratching my head. So, when the page was loaded only a few records from the total records will be displayed. user has to scroll all the way down the list to load next set of records, once the complete list loaded then user can't scroll down anymore. Here when the user scrolls down, a loading image with spinning icon is displayed and once the list loaded that image will not be displayed again when you scroll down to get next set of records then that loading image will display again. The element of that loading image will still be there in dom until all the list is loaded. 

in my script I tried waitproperty(visible, false, 5000), while loop with both exists and visible, but when the element is removed from the dom then I am getting the following error

"Unable to find the object "div[class*='MuiCircularProgress-determinate'][role='progressbar']". See Details for additional information. 13:49:32 Normal 11.37"

 

option1:

function waitUntil(element, PropValue, timeout){
var i=0
//var obj = Aliases.pageEmailAnalyticsGettingStarted.FindElement(element)
do
{
Delay(1000)
if (i==10){
break;
}
i++;
}while (Aliases.pageEmailAnalyticsGettingStarted.FindElement(element).Visible==false)
}

 

Option2.

while (Aliases.pageEmailAnalyticsGettingStarted.FindElement(element).Visible==true)

{

Delay(1000)

}

 

Option 3.

 

Can someone please help me how to fix this and verify if the object not exists and/or visible

 

Thanks

  • rrobinson's avatar
    rrobinson
    New Contributor

    I am brand new but have had a similar list/paging issue. I am still learning to find an object programmatically - however, I did get to the bottom of my list (see below) and verify it was loaded using a portion of my grid/list control that is always there - like the page navigation as an example to verify I was on page 1 - and using a list I know is not growing you could also verify the count or something as a text/context checkpoint.

     

    To scroll off the page vertically (the page was approximately 2 full screens so the bottom was well off the visible page), I just pressed the END key to get to the very bottom. Then defined some text checkpoint that would not be there if something failed.

     

    Hope that helps and yes this was a simple thing - but for me it worked!

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      Hello rrobinson, Thanks for your response. As you might notice that I am already using End key to scroll down to the page to load the next set of records. I have figured out the issue that the Exists and Visible properties returns true until all the records are loaded even though the visible is hidden. I looked at the VisibleonScreen and the value for that property changed to False when the result loaded, and the image is hidden. So I am using that property to verify and its working fine with my wait statement. But the issue still exists where once all the records are loaded the VisibleOnScreen is also throwing error that the object not found.

      How to verify the object is not Visibleonscreen in the If statement when it is completely removed from the DOM 

      code I changed to 


      function waitUntil(element, PropValue, timeout){
      var i=0
      do
      {
      if (!Aliases.pageEmailAnalyticsGettingStarted.FindElement(element).VisibleOnScreen){
      break;
      }
      Delay(2000)
      i++;
      }while (i<=10)

      }

       

      html source. The highlighted element will not change until all the records are loaded and that element will be removed from the dom.

      The loading image is what I am verifying.

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The UI Object must exist in the Object Browser in order to use WaitProperty Method.

     

    You can try using either WaitElement Method or WaitChild Method. 

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      Even I tried FindElements.length!=0 and still got the same error that unable to find the object. But finally I was able to fix the issue by modifying my code as below

       

      function waitUntil(element, PropValue, timeout){
      var i=0
      var obj = Aliases.pageEmailAnalyticsGettingStarted.FindElement(element)
      do
      {
      Delay(2000)
      if (obj.VisibleOnScreen==PropValue){
      break;
      }
      i++;
      }while (i<=10)
      }

      • rrobinson's avatar
        rrobinson
        New Contributor

        Nice! I like all the code examples I can find!  This is very helpful and happy that you sent this solution to me!!! Thanks a ton! Very nice solution here.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What browser, browser version and TC version are you using?

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      Hi rraghvani, I am using chrome V 108 and Chromium v108. TC v 15.44.1

      Also when I try using the Try Catch method the error is not caught and still getting same stale element or object not found. Is Try catch works for anyone using Javascript

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    First, see Supported versions of headless browsers.

     

    Second, I'm assuming you're using try...catch with the FindElement method? If that's the case, FindElement method returns an object that matches the specified search criteria. If no matching object was found, the method returns null. FindElement does not throw an error.

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      I am not using TC headless browser plugin, I am using selenium grid hub to run my test as headless. Does that still be a problem if the browser version is other than the one mentioned in that document?

       

      function BrowserRemote(env) {
      var server = seleniumaddress
      var capabilities = {
      "browserName": "chrome",
      "goog:chromeOptions": {
      "args": [
      "--headless",
      "--window-size=1920,1080",
      "--disable-gpu",
      "--disable-dev-shm-usage",
      "--no-sandbox"
      ]
      }
      };
      var url = getEnvURL(env);
      Browsers.RemoteItem(server, capabilities).Run(url);
      }