Send keys to page without an input element
15,544
I haven't tested it but would you mind give Actions.SendKeys
a try?
Example is in C#:
// without an element
new Actions(driver).SendKeys("abc").Perform();
// send keys to body
new Actions(driver).SendKeys(driver.FindElement(By.XPath("//body")), "abc").Perform();
Comments
-
Rob Walker almost 2 years
On a web page that has a
keypress
event listener running I want to be able to test sending keystrokes. But the page doesn't have an input element, and callingdriver.FindElement(By.XPath("//body")).SendKeys("abc");
Throws an error about needing the element to be editable to accept key strokes (against Chrome).
Is there any way to generate the keystrokes so the page sees them without injecting a dummy input element?
-
Rob Walker almost 11 yearsThanks -- that worked great. For anyone else looking Actions is in the OpenQA.Selenium.Interactions namespace