Wednesday, 4 September 2013

Keys in Selenium script | Webdriver

Key combinations made easier through Actions. Some of the popular keys were illustrated in this section; Similar key functions can be used for other keys from the image.

Enter/Return
driver.findElement(By.id("Value")).sendKeys(Keys.RETURN);
or|
driver.findElement(By.id("Value")).sendKeys(Keys.ENTER);

#PYTHON
from selenium.webdriver.common.keys import Keys
driver.find_element_by_name("Value").send_keys(Keys.RETURN)
or|
element = driver.find_element_by_id("Value")
element.send_keys("keysToSend")
element.submit()

#RUBY
element = @driver.find_element(:name, "Value")
element.send_keys "keysToSend"
element.submit
or|
element = @driver.find_element(:name, "Value")
element.send_keys "keysToSend"
element.send_keys:return


Down Arrow
driver.findElement(By.id("Value")).sendKeys(Keys.ARROW_DOWN);


TAB
Actions action =new Actions(driver);
action.sendKeys(Keys.TAB).sendKeys("keysToSend");
action.build().perform();

#PYTHON
driver.find_element_by_name("Value").send_keys(Keys.TAB)


Ctrl+End | Scroll to Bottom of the page
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();


Backspace
Actions actions = new Actions(driver);
actions.sendKeys(Keys.BACK_SPACE).perform();

#PYTHON
driver.find_element_by_name("Value").send_keys(Keys.BACKSPACE)
or|
driver.find_element_by_name("Value").send_keys(Keys.BACK_SPACE)




#PYTHON




2 comments: