Friday, 6 January 2017

How to Open New Tab with Selenium WebDriver

Selenium WebDriver  tool do not have any built In API using which we can directly use to open new tab. Normally we are using CTRL + t Keys to open new tab In Browser and cltr + tab to switch between the tabs. We will use this in our selenium test case to open another tab inside a browser and switch to tab. 

Check out the Example below in details to understand how to open a new tab, how to open particular url in the new tab, how to switch between two tabs  and how to close the tabs.




import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class BromiumTests {

 WebDriver driver;
 Utils util;

 @BeforeTest
 public void setUp() {
  System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver_win32\\chromedriver.exe");
  driver = new ChromeDriver();
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  
 }

 
 
 @Test
 public void testOpenYoutube() {
  driver.get("https://www.youtube.com");
  
  driver.get("https://www.youtube.com/watch?v=9NXEnGiOeUU");
  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

 }
        @Test
 public void testOpenGmail() {
  switchToNewTab();
  driver.get("http://www.gmail.com");
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 }
       public void openNewTab() {
  ((JavascriptExecutor) driver).executeScript("window.open('about:blank','_blank');");
 }

 public void switchToNewTab() {
  openNewTab();
  String subWindowHandler = null;

  Set<String> handles = driver.getWindowHandles();
  Iterator<String> iterator = handles.iterator();
  while (iterator.hasNext()) {
   subWindowHandler = iterator.next();
  }
  driver.switchTo().window(subWindowHandler);
 }

 @AfterClass
 public void tearDown() {
  driver.quit();
 }
 

}

57 comments:

  1. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    rpa Training in Bangalore

    ReplyDelete
  2. Nice Article, Please do post this kind of posts more, thanks.
    I wish you might like to have a look at my article http://javaseleniumworld.com/robot-class/

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
    ui path training in bangalore

    ReplyDelete
  5. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Sql&plsql Online Training

    workday Online Training

    SAP GTS Online Training

    Oracle BPM Online Training

    Oracle SCM Online Training

    ReplyDelete
  6. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Splunk Classes

    Tableau Classes

    ReplyDelete
  7. This is good piece of writing and pleasant urging commented
    here, I am really enjoying by these.

    ReplyDelete
  8. Hey, very nice site. I came across this on Google, and I am stoked that I did. I will definitely be coming back here more often. Wish I could add to the conversation and bring a bit more to the table, but am just taking in as much info as I can at the moment. Thanks for sharing.

    Custom Web Application Development

    ReplyDelete
  9. Do not think! Just come with us to BGAOC and play with us. best casino games come to us and win soon.

    ReplyDelete
  10. buy soma pill 350mg
    Soma pill 350mg has carisoprodol that effectively treats acute pain in people. Pain is felt by almost everyone at some point of their life. This can at times make the life of the person very difficult. Soma pill 350mg has helped people all over the world. So use soma pill 350mg and get rid of all your body pain. Buy soma pill online and have a healthy pain free life.

    ReplyDelete
  11. BGAOC is the best online casino I've played. playing casino games Win as no one wins.

    ReplyDelete
  12. Супер отличная гибкая світлодіодна стрічка на любой вкус и цвет, обычно покупаю в интернет магазине.

    ReplyDelete
  13. No.1 Astrologer +91-9898765059 Best Jyotish Ahmedabad Astrologer Mahendra Joshi


    URL:


    http://astrologyindia.in

    Website :- www.astrologyindia.in

    ReplyDelete
  14. Thank you so much for the sharing it was useful and very informative. We're leading interior designers in chennai, we do all interior contract work.

    ReplyDelete
  15. One of the most trustworthy software to assist us call at immediate past may be the wondrous application of QuickBooks. QuickBooks Support Phone Number Running a business, it offers revolutionized our banking and changed the messy way we do finances. However, perhaps the best software often faces many errors during its functioning. Quite often, when utilizing QuickBooks, you would run into QuickBooks error code 15106 in your screen to get tantalized by it. However, nothing is to worry in this regard.

    ReplyDelete
  16. I love this post.

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสมาชิกที่นี่ >>> Gclub online

    ReplyDelete
  17. Very cool!

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีเกมส์สล็อตออนไลน์ 1688 slot อีกมากมายให้คุณได้ลอง
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688

    ReplyDelete
  18. QuickBooks Payroll Support Phone Number
    management quite definitely easier for accounting professionals. There are so many individuals who are giving positive feedback if they process payroll either QB desktop and online options

    ReplyDelete
  19. Nice Post thanks for the information, good information & very helpful for others. For more information about Why need Free Online Career Counselling & What Is Career Counselling? Career Counselling is a process that focuses on helping Click Here to Read More

    ReplyDelete
  20. IN QuickBooks Enterprise Support Phone Number All of them would be best inside their respective work area nevertheless when there clearly was a tiny glitch or error comes that might be a logical error or a technical glitch, can result producing or processing wrong information into the management or may wind up losing company’s precious data.

    ReplyDelete
  21. You might have trapped into a problem with Intuit product and payroll services? You're going to be ready to understand the best approach to get your hands on the Quickbooks Support Number. We welcome you 24*7 to access the various support services of Intuit products asking for help.

    ReplyDelete
  22. You will discover so many fields it covers like creating invoices, managing taxes, managing payroll etc. However exceptions are typical over, sometimes it makes the down sides and user wants QuickBooks Tech Support Number client Service help.

    ReplyDelete
  23. You will get some technical glitch. You will have errors also. Where do you realy turn? Take assistance from us straight away. We are going to provide full support to you. You are able to cope with the majority of the errors. We need to just coach you on something.
    VISIT : https://www.customersupportnumber247.com/

    ReplyDelete
  24. You could get resolve all of the major issues include installations problem, data access issue, printing related issue, software setup, server not responding error etc with our Quickbooks Support Phone Number.

    ReplyDelete
  25. The QB technicians are spontaneous and diligent to fix any QB issue , So business now save money as well time by calling the experts . One you connect with them the techies here to help you the best way they can. They are prompt and responsive in resolving the issue. Resolve any Quickbooks technical issue by the QuickBooks Suppport Phone Number.

    ReplyDelete
  26. Firstly, click on file and choose the chance Open & Restore. QuickBooks Support Phone Number Now open the file and click on Update Company File for New Version. And now maybe you are all set.

    ReplyDelete
  27. isn't an issue for all of us because problems try not to come with any pre-announcements. QuickBooks Support Phone Number There might be occasions once you might face some form of delay in reaching us,

    ReplyDelete
  28. The software has transformed and helped small & medium sized companies in many ways and managed their business successfully. The smart accounting software is richly featured with productive functionalities that save time and accuracy of the work. As it is accounting software, from time to time you may have a query and will seek assistance. This is the reason why QuickBooks has opened toll free Quickbooks Support. For telephone assistance just call or email to support team

    ReplyDelete
  29. The QuickBooks Payroll Tech Support Number has many awesome features that are good enough when it comes to small and middle sized business. QuickBooks Payroll also offers a dedicated accounting package which include specialized features for accountants also.

    ReplyDelete
  30. Sometimes it’s normal for users to have some performance-related issues in your QuickBooks due to your virus in your personal computer or some other computer related issues.In that case, you are annoying and you need some support to help you out. Here you can easily call us at our QuickBooks Payroll Support Phone Number to get instant help from our technical experts. However, if you would like speak to us quickly, you can easily reach us at QuickBooks Customer Support Number and all your queries may be solved instantly.

    ReplyDelete
  31. As QuickBooks Tech Support Phone Number Premier has various industry versions such as retail, manufacturing & wholesale, general contractor, general business, Non-profit & Professional Services, there is innumerous errors that will create your task quite troublesome.

    ReplyDelete
  32. Fix all of the issues for QuickBooks Payroll Support phone Number Desktop Payroll Basic, Standard, & Payroll Assisted. Check out the aforementioned number to get hold of our ProAdvisor to possess support for QuickBooks online Payroll support, Intuit Online & Full Service Payroll.

    ReplyDelete
  33. About having the most desirable and efficacious help on every issue you may possibly encounter yourself with. You merely need certainly to avail the assistance through the technical experts by dialing the QuickBooks Support Number.

    ReplyDelete
  34. The QuickBooks Payroll Support team at site name is held accountable for removing the errors that pop up in this desirable software. We care for not letting any issue can be purchased in in the middle of your work and trouble you in undergoing your tasks.

    ReplyDelete
  35. QuickBooks has almost changed it is of accounting. Nowadays accounting has exploded to become everyone’s cup of tea and that’s only become possible because because of the birth of QuickBooks accounting software. We have the best and the most convenient answer to enhance your productivity by solving every issue you face with the software. Give us a call at Support For QuickBooks to avail the greatest customer service services designed for you.

    ReplyDelete
  36. Call us any moment to get best answers to all or any the QuickBooks Payroll Error Support issues that you may come across with. QuickBooks payroll is quite promising, advanced and end to get rid of business accounting software.

    ReplyDelete
  37. Contact QuickBooks Support for prompt solutions. The QuickBooks Error Code 3371 is adept at providing pragmatic solutions that are probably the most strongly related your concerns.

    ReplyDelete
  38. Accurate Payroll Calculations the program will do all the math and keep close track of the tax rates and helps you calculate the QuickBooks Payroll support Phone with ease. The calculations are infallible as well as on time.

    ReplyDelete
  39. The guide might have helped you understand QuickBooks file corruption and methods to resolve it accordingly. If you would like gain more knowledge on file corruption or any other accounting issues, then we welcome you at our professional support center. It is simple to reach our staff via QuickBooks Payroll Tech Support & get required suggestion after all time. The group sitting aside understands its responsibility as genuine & offers reasonable assistance with your demand.

    ReplyDelete
  40. QuickBooks Enterprise Support Telephone Number Is Here to assist ease Your Accounting Struggle QuickBooks Support provides end-to end business accounting experience

    ReplyDelete
  41. You'll be able to very easily keep an eye on 50 employees at the same time and you also can monitor the sheer number of working hours of each employee. It helps you in calculating the complete soon add up to be paid to a worker depending through to the QuickBooks Payroll Support Number of hours he/she has contributed in their work.

    ReplyDelete
  42. The most unique feature of our team QuickBooks Payroll Support Phone Number is that it really is available for you 24*7. It works hard towards providing you with the greatest customer support and concentrate on achieving maximum customer care.

    ReplyDelete
  43. We offers you QuickBooks Enterprise Support Phone Number Team. Our technicians be sure you the security associated with the vital business documents. We have a propensity never to compromise utilizing the safety of one's customers.

    ReplyDelete