Skip to content

Instantly share code, notes, and snippets.

@yucer
Created August 9, 2017 09:18
Show Gist options
  • Save yucer/93ae7c343aa33904a83dc8d13802b6ca to your computer and use it in GitHub Desktop.
Save yucer/93ae7c343aa33904a83dc8d13802b6ca to your computer and use it in GitHub Desktop.
Test sendKeys with CONTROL + T using Selenium Java
package automationFramework;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class FirsttestCase {
/**
* @param args
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args) throws InterruptedException, IOException {
BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
System.setProperty("webdriver.firefox.bin", "/home/yucer/Downloads/softlib/firefoxes/2017-08-05-10-03-34-mozilla-central-firefox-57.0a1/firefox");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(Level.FINEST);
FirefoxDriver driver = new FirefoxDriver(options);
System.out.print("Openning about window.");
driver.get("about:");
Thread.sleep(4000);
driver.get("http://www.google.com");
System.out.print("Selecting the element.");
WebElement element = driver.findElement(By.id("lst-ib"));
System.out.print("Opening new Tab");
element.sendKeys("abcdef");
Thread.sleep(7000);
element.sendKeys(Keys.CONTROL + "t" + Keys.CONTROL);
System.out.println("\n You should see only 12345 text now because of the undo.\n");
Thread.sleep(7000);
System.out.print("Closing the browser");
driver.quit();
Thread.sleep(5000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment