Forum Discussion

sriram_sig's avatar
sriram_sig
Contributor
6 years ago
Solved

How to perform action on a new tab opened during test run

I have a testcase wherein by clicking on a link, a new tab is opened and have to fill a form on this new tab

i'm openign a new browser using the below code

Sys.Browser("chrome").BrowserWindow(0).Keys("^n")
 Sys.Browser("chrome").ToUrl("URL1")

and then assigning the heirarchy with the page to a variable. and perform actions on this page

a = Sys.Browser("chrome").Page("page1")
a.FindChildByXPath("//input[@id='Subject']").SetText("Testing")
a.FindChildByXPath("//button[@id='addButton']").click()

And after executing the last line, it opens up a new tab and then i am reassigning to another variable

b = Sys.Browser("chrome").Page("page2")
b.FindChildByXPath("//ul[@id=''Venue"]).click()

I'm getting an error "trying to perform action on a zero-sized window" during the click operation. Is there a better way to do this

Note - Page1 and Page2 are from NameMapping

  • You mention that Page1 and Page2 are from NameMapping... but I don't see any NameMapping references in your code.  I would expect to see Aliases.browser.page1 for a reference via NameMapping.  

     

    In any case... here's my thinking.  There is a click action that opens another tab and renders page2. I'm assuming, though, that there is a delay in that rendering.  The code you have below has no code to "wait" for the page to complete loading before you interact with it.  The "Venu" object you're trying to find MAY be present, but if the page hasn't fully rendered yet, it may not have dimensions making it clickable.

    After each navigation to a page, you should call the "Wait" method on that page.  That will wait for the page to render.  THEN you can perform your actions against it.

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You mention that Page1 and Page2 are from NameMapping... but I don't see any NameMapping references in your code.  I would expect to see Aliases.browser.page1 for a reference via NameMapping.  

     

    In any case... here's my thinking.  There is a click action that opens another tab and renders page2. I'm assuming, though, that there is a delay in that rendering.  The code you have below has no code to "wait" for the page to complete loading before you interact with it.  The "Venu" object you're trying to find MAY be present, but if the page hasn't fully rendered yet, it may not have dimensions making it clickable.

    After each navigation to a page, you should call the "Wait" method on that page.  That will wait for the page to render.  THEN you can perform your actions against it.

    • sriram_sig's avatar
      sriram_sig
      Contributor

      In this case, page1 and page2 are the URLs of the webpage, yes you are right it does not come directly from the name mapping. I will try out the solution provided.

    • Marsha_R's avatar
      Marsha_R
      Champion Level 3

      If a script that I think is obvious isn't giving me the results I wanted, I try recording the same test to see if TestComplete is using the same object names or if it can't find the objects, so then I have a clue where to start looking.