Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97778

How to press CTRL+T and CTRL+TAB in selenium WebDriver using Java?

$
0
0

Hi All,

For one of my project I need to open a new tab and navigate between the tabs for the same I need to know how can I press CTRL+T and CTRL+TAB in Selenium Webdriver using Java.

Please let me know how can I do the same.Thank You...!!!

I'm using the below:

Firefox Version: 48.0.2

Java Version: 1.8

Selenium WebDriver Version: 3.0.0

OS: Windows 10

I tried the below code but it doesn't seems to be working:

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

public class Handling_Tabs {

    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com/");
        System.out.println(driver.getTitle());
        driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL+"t");
        driver.get("http://www.bing.com/");
        System.out.println(driver.getTitle());
        driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL+"\t");
        System.out.println(driver.getTitle());      
    }
}

Viewing all articles
Browse latest Browse all 97778

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>