如何在selenium webdriver(java)中发送键盘组合键?

Ibe*_*y I 2 selenium-webdriver

我想将1999发送到Selenium WebDriver(java)中的文本框.当我尝试在sendkeys之前将键击组合成一个字符串时,以下代码不起作用:

String allKeys = Keys.NUMPAD1 + Keys.NUMPAD9 + Keys.NUMPAD9 + Keys.NUMPAD9; 
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

对于参数类型org.openqa.selenium.Keys,org.openqa.selenium.Keys,运算符+未定义.

小智 6

而不是使用:

String allKeys = Keys.NUMPAD1 + Keys.NUMPAD9 + Keys.NUMPAD9 + Keys.NUMPAD9; 
Run Code Online (Sandbox Code Playgroud)

你应该使用:

driver.findelement(by.xpath(xpathExpr)).sendkeys(Keys.NUMPAD1, Keys.NUMPAD9, Keys.NUMPAD9, Keys.NUMPAD9);
Run Code Online (Sandbox Code Playgroud)

或使用:

String allKeys = "1999";
driver.findelement(by.xpath(xpathExpr)).sendkeys(allKeys);
Run Code Online (Sandbox Code Playgroud)


gSr*_*gSr 2

为什么不使用发送键。

driver.findelement(by.xpath(xpathExpr)).sendkeys("1999");
Run Code Online (Sandbox Code Playgroud)