Closing the current Tab in the Chrome browser
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Closing the current Tab in the Chrome browser
Hi,
I have a dashboard page open in the chrome browser. Here I search for an entity which opens up in a new tab, I veryfy some information on this and want to close this tab and go back to the dashboard page. I have to repeat this process at least 10 times for different entities.
I'ven't had any success in closing the tab consistently. Most of the time, this ends up closing the 'dashboard' page itself.
Here is what I'm using:
////////////////////Main////////////////////////////////////////////////// function main(){ /* Here goes the complete program to run the test */ // closing the current tab CloseTab(getURL()); } ///////////////////// Close the current tab in the browser ///////////////// function CloseTab(URL) { var browser = Sys.Browser("*"); var page = browser.Page("*"); Sys.Browser().Page(URL).Keys("^w") } /////////////////fetch the URL of current page in the browser/////////////// function getURL(){ var browser = Sys.Browser("Chrome"); var page = browser.Page("*"); var url = page.URL; return url; }
Any help would be appreciated!
Thank you
Abhi
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here's a previous thread that may help:
Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Every URL is a "page" in the object tree of TestComplete. So, simply selecting Browser.Page('*') isn't going to get the current page necessarily. The "current" page is identifed by whether or not the "Visible" property is true.
So, in your getURL, I would actually search for whatever page object is currently visible.
function getURL(){ var browser = Sys.Browser("Chrome"); var page = browser.FindChild(["ObjectType", "Visible"],["Page", true], 0); var url = page.URL; return url; }
Robert Martin
[Hall of Fame]
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Robert!
I tired this solution, and it worked well the first time, but when I was re-running the tests, same old thing started occuring again. It was closing the main dashboard page.
Thank you
Abhi
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another possiblity then is a timing issue. If your code to close the tab is happening before the tab is recognized by TestComplete's object recognition, that could be the issue. That's basically what this seems to be.
Robert Martin
[Hall of Fame]
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
