cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

4 REPLIES 4
Highlighted
Community Manager

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

@tristaanogre@AlexKaras@Marsha_R@shankar_r, your suggestions are welcome Smiley Happy

---------
Tanya Gorbunova
SmartBear Community Manager

 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!
Highlighted
Community Hero

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

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.

 

 

Highlighted
Community Hero

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

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Highlighted
Contributor

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

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.