Forum Discussion

whuang's avatar
whuang
Regular Contributor
6 years ago

Why TC keeps waiting until the time expire while I can see the object I am waiting for is there

Hi Guys,

 

I was trying to get TC to click on a link and then click on another link on the page after. So I used a WaitChild method in the script, but it keeps waiting on the page until the 30 seconds expired, but I can see the object that I was waiting for was showing on the page as soon as the first link was clicked. Same issue when I used the WaitProperty method instead of the WaitChild. Can anyone tell me what wait method I should use in order to avoid uneccessary waiting?

 

sys.Browser("*").Page("*").Find("contentText","Photo, Video & Design",30).Click
call Sys.Browser("*").Page("*").WaitChild(Sys.Browser("*").Page("*").Find("contentText","Corel",30),30000)
sys.Browser("*").Page("*").Find("contentText","Corel",30).Click

 

Thanks!

 

 

  • Hi,

     

    Possible code (assuming that the initial page is already opened in the browser):

    Dim page
    Dim oControl
    
    Set page = sys.Browser("*").Page("*<yourCompany>.com*")
    Set oControl = page.Find("contentText", "Photo, Video & Design", 30)
    If (oControl.Exists) Then
      Call oControl.Click()
    Else
      Call Log.Warning("Web element with the 'Photo, Video & Design' text was not found", , , , page.PagePicture)
    End If
    Call page.Wait() ' waits until new page is loaded
    
    Set oControl = page.Find("contentText", "Corel", 30)
    If (oControl.Exists) Then
      Call oControl.Click()
    Else
      Call Log.Warning("Web element with the 'Corel' text was not found", , , , page.PagePicture)
    End If
    Call page.Wait()
    

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Can you provide the final test log?

    My expectation is that there are problems reported to the log caused by the fact that there is more than one browser process running in your system at the moment of test execution.

    Basically, your test code commands this:

    First line of code:

    > sys.Browser("*").Page("*").Find("contentText","Photo, Video & Design",30).Click

    -- Look for any browser process running in the system;

    -- For the found arbitrary browser, get any page opened in it;

    -- Within this page look for the web element with the "Photo, Video & Design" text;

    -- Click on the found element.

     

    Obviously, if, say, some browser process is running in the background with no page opened and this will be the process that TestComplete finds first, TestComplete will wait for the page and other web page elements.

     

    Second line of code:

    > call Sys.Browser("*").Page("*").WaitChild(Sys.Browser("*").Page("*").Find("contentText","Corel",30),30000)

    -- Look for any browser process running in the system. Note - the found browser process well might be not the same that was used on previous step. This is because you are not reusing found process, but do search a-new;

    -- For the found arbitrary browser, get any page opened in it. Same problem with the page;

    -- Within this page, wait for a child web element, that is located on an arbitrary page of an arbitrary browser process that (web element) has the 'Corel' text. Again, note, that the first and second browser processes used in this line of code, likewise their respective pages, might be absolutely different ones (and differ from those found on first line) because you perform a search every time but do not reuse the found objects.

     

    Third line of code:

    > sys.Browser("*").Page("*").Find("contentText","Corel",30).Click

    -- Look for any browser process running in the system. Again, the found browser process can be different than those been found previously;

    -- For the found arbitrary browser, get any page opened in it. Same problem here;

    -- Within this page look for the web element with the "Corel" text;

    -- Click on the found element.

     

    • whuang's avatar
      whuang
      Regular Contributor

      Hi AlexKaras , I am new to TC and scripting, so I am kind of learning both at the same time.Here is the log screenshoot. There was only Chrome running, I killed Edge running at the back before running the test. How can I store and reuse the search result from the second line?

      Update - I end up using sys.Browser("*").Page("*") to wait for the page to load and then continue the next step. It is much faster and it doesn't wait for unnecessary time. Is it safe to say that all the properties and objects are available to access once the wait is done by using this Wait method?

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Possible code (assuming that the initial page is already opened in the browser):

        Dim page
        Dim oControl
        
        Set page = sys.Browser("*").Page("*<yourCompany>.com*")
        Set oControl = page.Find("contentText", "Photo, Video & Design", 30)
        If (oControl.Exists) Then
          Call oControl.Click()
        Else
          Call Log.Warning("Web element with the 'Photo, Video & Design' text was not found", , , , page.PagePicture)
        End If
        Call page.Wait() ' waits until new page is loaded
        
        Set oControl = page.Find("contentText", "Corel", 30)
        If (oControl.Exists) Then
          Call oControl.Click()
        Else
          Call Log.Warning("Web element with the 'Corel' text was not found", , , , page.PagePicture)
        End If
        Call page.Wait()