How to open a new tab using selenium webdriver


package selenium_examples;


import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;



public class spicejet {

public static void main(String[] args) {


 WebDriver driver = new FirefoxDriver();

 driver.get("http://www.google.com");

     driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
   
     System.out.println("New Tab Opened");
   
     driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"w");
   
     System.out.println("New Tab Closed");

}
  }


Output:-

New Tab Opened
New Tab Closed



Script to go back to first tab i,e google.com page

package selenium_examples;


import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;



public class spicejet {

public static void main(String[] args) {


 WebDriver driver = new FirefoxDriver();

 driver.get("http://www.google.com");

     driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
   
     System.out.println("New Tab Opened");
   
     driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL , Keys.TAB);
   
 
}
  }

No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge