如何将Keys.Tab作为参数发送到函数

时间:2014-07-09 07:02:24

标签: selenium parameters key send

我的代码如下:

void someFunc(){
driver.findElement(By.xpath(OR.getProperty("Nodes_AddNodeDescriptionInput"))).sendKeys(Keys.TAB);
}

将密钥Tab发送到提到的xPath。 但我想避免驱动程序... someFunc()中的详细信息,所以我希望有一个代码用以下代码替换上面的代码。

if(!sendKeyboardKeysByXpath("Nodes_AddNodeDescriptionInput", Keys.TAB)) {
printError("Failed to send the Tab key.");
return(false);
}

sendKeyboardKeysByXpath的默认值:

public static boolean sendKeyboardKeysByXpath(String xPathKey, CharSequence... textToType) {
printLogs("Calling sendKeyboardKeysByXpath with values: " + xPathKey + ", " + textToType);
try {
printLogs("Typing '"+ textToType + "' to " + xPathKey);
if(!checkElementPresenceByXpath(xPathKey)) {
printFunctionReturn(fn_fail);
return(false);
}   
driver.findElement(By.xpath(OR.getProperty(xPathKey))).clear();
driver.findElement(By.xpath(OR.getProperty(xPathKey))).sendKeys(textToType);
} 
catch(Throwable t) {
ErrorUtil.addVerificationFailure(t);
printError("sendKeysByXpath: Exception occurred while typing keys.");
printFunctionReturn(fn_fail);
return(false);
}
return(true);
} 

如何将Keys.Tab作为参数发送。我在sendKeyboardKeysByXpath函数中获取了垃圾值

1 个答案:

答案 0 :(得分:0)

使用Keys.TAB.name()它会写TAB

因此,在您的日志方法中,它将是textToType.name()