1.

How to send ALT/SHIFT/CONTROL key in Selenium WebDriver?

Answer»

When we use ALT/SHIFT/CONTROL keys, we hold onto those keys and click other buttons simultaneously to achieve the SPECIAL functionality.

To  hold onto these keys while SUBSEQUENT keys are pressed, you need to define two more methods: keyDown(modifier_key) and keyUp(modifier_key)

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)

The purpose is to PERFORM a modifier key press and not to release the modifier key. Subsequent interactions may assume it’s kept pressed.

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)

The purpose is to Perform a key release.

With a combination of these two methods, you can capture the special function of a particular key.

public static void main(String[] args)  { String baseUrl = “HTTPS://www.facebook.com”; WebDriver DRIVER = new FirefoxDriver(); driver.get("baseUrl"); WebElement txtUserName = driver.findElement(By.id(“Email”); Actions builder = new Actions(driver); Action seriesOfActions = builder  .moveToElement(txtUserName)  .click()  .keyDown(txtUserName, Keys.SHIFT)  .sendKeys(txtUserName, “hello”)  .keyUp(txtUserName, Keys.SHIFT)  .doubleClick(txtUserName);  .contextClick();  .build(); seriesOfActions.perform(); }


Discussion

No Comment Found