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 calling
driver.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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With