Saturday, January 7, 2017

Multi tabs handling Using Selenium

Using Robot We can Handle Multiple Tabs in Selenium

package samples;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

/**
 *
 * @author krishnareddy
 *
 */
public class MultiTabs {

@Test
public void multiTabs() throws AWTException {

// System.setProperty("webdriver.chrome.driver",
// "Drivers\\chromedriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gtpvkr.in/2014/08/handling-authentication-dialog-box.html");
;
// driver.findElement(By.xpath(""));

//open new tab
new Actions(driver)
.contextClick(
driver.findElement(By
.xpath("//*[@id='rsidebar-wrapper']/div[1]/div/a[4]/img")))
.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build()
.perform();

// System.out.println(driver.getWindowHandles().size());

Robot robot = new Robot();

/*
* robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_TAB);
*
* robot.keyRelease(KeyEvent.VK_CONTROL);
* robot.keyRelease(KeyEvent.VK_TAB);
*/

//close current tab
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_W);

robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_W);

//get current tab title
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
System.out.println(driver.getTitle());

//click on any element
driver.findElement(By.xpath("//*[@id='nav-legal']/li[1]/a")).click();

//get back previous tab
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_T);

robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_T);

}
}

44 comments :

  1. Thanks for Sharing this blog it is very helpful to us ...... Selenium Online Training

    ReplyDelete

  2. Thank you for this great article which is about multi tabs handling using selenium .keep more updates.
    SEO Company in India

    ReplyDelete
  3. Very Nice...Contains A to Z concepts...Thanks a lot.. and looking for the best selenium training in Chennai with certification from us. we have experienced selenium experts offer selenium course training with industry exposure. Check Here https://goo.gl/VRNEXv

    ReplyDelete
  4. The Blog gave idea to set up multitabs using selenium The Code Shared are very much useful My sincere thanks for sharing this post Please Keep on sharing this type of post
    Selenium Training in Bangalore

    ReplyDelete
  5. Thanks for sharing this article. Really useful for me to understand about selenium multi tabs handling. software testing training in Bangalore

    ReplyDelete
  6. Really very nice informative article about the multi tabs handling... Keep in blogging regularly to update these kinds of useful informative...
    Selenium Training in Velachery|Best Selenium Training in Velachery|Selenium Training in Chennai

    ReplyDelete
  7. It’s a shame you don’t have a donate button! I’d certainly donate to this brilliant blog! I suppose for now I’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this blog with my Facebook group. Chat soon!
    <a href="http://www.traininginmarathahalli.in/selenium-training-in-bangalore/”> Selenium Training in Marathahalli </a>|

    ReplyDelete
  8. awesome post presented by you..your writing style is fabulous and keep update with your blogs.
    selenium Online Training Bangalore

    ReplyDelete
  9. Excellent Article ...thank u for sharing, such a valuable content Learners to get good knowledge after read this article.. Selenium Training in Chennai | Selenium Training in Chennai

    ReplyDelete
  10. This is one awesome blog article. Much thanks again. selenium Online course Hyderabad

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

    ReplyDelete
  12. With practical you described selenium with java, it will be very helpful. Thank you so much.

    Selenium Testing Training in Pune

    ReplyDelete
  13. At Coepd - (Center of Excellence for Professional Development) Manual & Selenium testing training program is designed to give participants the skills & knowledge to gain a competitive advantage in starting/enhancing a career in software testing. We provide the attendee's software testing service which is required to ensure that tested applications meet all application requirements. Participants receive up-to-date training in multiple areas in Software Testing and a thorough understanding of real-world projects. Our collaborative ecosystem comprising of Partnerships with Software Companies enables real time software test life cycle experience.

    http://www.coepd.com/TestingTraining.html

    ReplyDelete
  14. I like your post and appreciate your effort in this code. Keep sharing also in future. It will be really helpful for us. Thanks a lot.

    selenium training in pune
    selenium training institute in pune

    ReplyDelete
  15. I‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things... RPA Training in Chennai | Blue Prism Training in Chennai

    ReplyDelete
  16. Thanks for sharing the more valuable information to share with us. For more information please visit our website. Testing Tools Training in Hyderabad

    ReplyDelete
  17. Thanks for sharing this valuable information to our vision

    RPA Online Training in Hyderabad

    ReplyDelete
  18. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 
    Java training in Chennai | Java training in Annanagar | Java training in Chennai

    Java training in Chennai | Java training in Bangalore | Java training in Electronic city

    ReplyDelete
  19. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
    python course in pune | python course in chennai | python course in Bangalore

    ReplyDelete
  20. Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
    Java training in Chennai | Java training in Bangalore

    Java online training | Java training in Pune

    ReplyDelete
  21. After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
    python course institute in bangalore
    python Course institute in bangalore
    python course institute in bangalore

    ReplyDelete
  22. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in chennai

    automation anywhere online Training

    ReplyDelete
  23. In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips to help him learn and master in Angularjs. I like your writing style and I hope you will keep doing this good working.
    Angularjs Training in Bangalore
    Angularjs Training Institute In Bangalore
    Angularjs Course in Bangalore
    Android Institute in Bangalore
    Android Coaching in Bangalore
    Android Coaching Center in Bangalore

    ReplyDelete
  24. Well with your permission let me grab your RSS feed to keep updated with forthcoming post. Thanks a million, and please keep up the gratifying work.
    industrial course in chennai

    ReplyDelete
  25. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on
    updating…

    Education
    Technology

    ReplyDelete
  26. I just love smart home automation, it makes things so much fun and easier for us. My sister has just install a project like this in their home and they are very satisfied. Thanks for your prolonged articles I will also get one. Keep sharing the good stuff.

    ReplyDelete
  27. Hi there! I simply want to offer you a huge thumbs up for your great information you have here on this post. I am coming back to your blogfor more soon.

    ReplyDelete
  28. Great information. Lucky me I came across your website by chance. I've book-marked it for later!
    UI Development Training in Bangalore
    Reactjs Training in Bangalore

    ReplyDelete
  29. Such an excellent and interesting blog, do post like this more with more information, this was very useful. Salesforce Training India  

    ReplyDelete
  30. Wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.

    Data Science

    Python

    Selenium

    ETL Testing

    AWS

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

    ReplyDelete
  32. This blog, in my opinion, is among the best because it has been quite beneficial to me. I appreciate you sharing this useful information.
    IELTS Coaching in Vadodara

    ReplyDelete