How to send keyboard keys combination in selenium webdriver (java)?
Problem? 😦
How to send keyboard keys combination in selenium webdriver (java)?
Solution: 🙂
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; public class TestKeyboardKeysCombination { public static void main(String[] args) throws InterruptedException { DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); System.setProperty("webdriver.ie.driver", "C://IEDriverServer.exe"); WebDriver myTestDriver = new InternetExplorerDriver(capabilities); myTestDriver.get("https://www.google.com/"); myTestDriver.manage().window().maximize(); myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); myTestDriver.findElement(By.xpath("//*[@id='gs_tti0']")).sendKeys(Keys.NUMPAD1, Keys.ADD, Keys.NUMPAD9, Keys.EQUALS,Keys.ENTER); Thread.sleep(10000L); myTestDriver.quit(); } }
Start multiple browser using IE, Firefox, Chrome – Learn By Example
import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; public class Multiple { public static void main(String[] args) throws InterruptedException { //Open InternetExplorer browser // Method and Description - static DesiredCapabilities internetExplorer() DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); //Method and Description - void setCapability(java.lang.String capabilityName, boolean value) capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); //Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined "properties"; a means of loading files and libraries; and a utility method for quickly copying a portion of an array. System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer.exe"); //InternetExplorerDriver(Capabilities capabilities) WebDriver driver = new InternetExplorerDriver(capabilities); driver.manage().window().maximize(); driver.get("http://google.com"); // Open FireFox Browser WebDriver driverFireFox1 = new FirefoxDriver(); driverFireFox1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); driverFireFox1.manage().window().maximize(); driverFireFox1.get("http://seleniumhq.org"); // Open Google Chrome Browser System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); WebDriver driverChrome = new ChromeDriver(); driverChrome.manage().window().maximize(); driver.get("http://google.com"); Thread.sleep(5000L); driver.close(); driverChrome.close(); driverFireFox1.close(); } }