Skip to content

Instantly share code, notes, and snippets.

@yucer
Created August 11, 2017 08:50
Show Gist options
  • Save yucer/6516803bcf3027c10417c836949310a2 to your computer and use it in GitHub Desktop.
Save yucer/6516803bcf3027c10417c836949310a2 to your computer and use it in GitHub Desktop.
Test sendKeys with CONTROL + T using Selenium Java with Electrolysis disabled
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-10-10-02-55-mozilla-central-firefox-57.0a1/firefox");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(Level.FINEST);
options.addPreference("browser.tabs.remote.autostart", false);
options.addPreference("browser.tabs.remote.autostart.1", false);
options.addPreference("browser.tabs.remote.autostart.2", false);
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");
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