Chrome:
File file = new File("D:/Selenium/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // optional
Firefox:
File pathBinary = new File("C:\\Program Files (x86)\\firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile(firefoxBinary,firefoxProfile);
OR
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\firefox\\firefox.exe");
/**
* via actions
*/
Actions newTab=new Actions(driver);
newTab.keyDown(Keys.SHIFT).click(driver.findElement(By.xpath("//input[@id='gh-btn']"))).keyUp(Keys.SHIFT).build().perform();
/**
* via js
*/
((JavascriptExecutor)driver).executeScript("window.open();");
System.out.println(driver.getWindowHandles());
driver.switchTo().window((driver.getWindowHandles().toArray())[1].toString());
Cookie ck = new Cookie(name,value,domain,path,date);
System.out.println(ck);
driver.manage().addCookie(ck);
Click on element by id
JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("document.getElementById('gh-eb-Geo-a-en').click();");
Actions actions = new Actions(driver);
actions.moveToElement(language).perform();
WebElement element = driver.findElement(By.id("gh-eb-Geo-a-en"));
actions.moveToElement(element2);
actions.click().build().perform();