通过getElementsByID找不到的情况下,可以通过nodelist的循环获取到item,进行操作
@FXML
void automeetingAction(ActionEvent event) {
Document doc = webview.getEngine().getDocument();
NodeList inputNodeList = doc.getElementsByTagName("input");
for (int i = 0; i < inputNodeList.getLength(); i++) {
NamedNodeMap attrs = inputNodeList.item(i).getAttributes();
Node type = attrs.getNamedItem("type");
String typeStr = "";
if (type != null) {
typeStr = attrs.getNamedItem("type").getTextContent();
}
Node placeholder = attrs.getNamedItem("placeholder");
String placeholderStr = "";
if (placeholder != null) {
placeholderStr = attrs.getNamedItem("placeholder").getTextContent();
}
if (!"".equals(typeStr) && !"".equals(placeholderStr)) {
if ("text".equals(typeStr) && "议主题".equals(placeholderStr)) {
HTMLInputElement buttonThis = (HTMLInputElement) inputNodeList.item(i);
try {
buttonThis.setValue(getURLParam(webview.getEngine().getLocation(),"problemSummary"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
//选择外部会议
if (null != inputNodeList.item(i).getParentNode().getNextSibling() && "会议".equals(inputNodeList.item(i).getParentNode().getNextSibling().getTextContent())) {
HTMLInputElement buttonThis = (HTMLInputElement) inputNodeList.item(i);
buttonThis.click();
}
//选择立即开始
if (null != inputNodeList.item(i).getParentNode().getNextSibling() && "立即开始".equals(inputNodeList.item(i).getParentNode().getNextSibling().getTextContent())) {
HTMLInputElement buttonThis = (HTMLInputElement) inputNodeList.item(i);
buttonThis.click();
}
//选择遵守安全规则
if (null != inputNodeList.item(i).getParentNode().getNextSibling() && "我承诺遵守以上安全规则".equals(inputNodeList.item(i).getParentNode().getNextSibling().getTextContent())) {
HTMLInputElement buttonThis = (HTMLInputElement) inputNodeList.item(i);
buttonThis.click();
}
}
NodeList textareaNodeList = doc.getElementsByTagName("textarea");
for (int i = 0; i < textareaNodeList.getLength(); i++) {
NamedNodeMap attrs = textareaNodeList.item(i).getAttributes();
Node placeholder = attrs.getNamedItem("placeholder");
String placeholderStr = "";
if (placeholder != null) {
placeholderStr = attrs.getNamedItem("placeholder").getTextContent();
}
if (!"".equals(placeholderStr)) {
if ( "请输入外部邮箱".equals(placeholderStr)) {
HTMLTextAreaElement buttonThis = (HTMLTextAreaElement) textareaNodeList.item(i);
try {
buttonThis.setValue(getURLParam(webview.getEngine().getLocation(),"reportContactEmail"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
if ( "请输入".equals(placeholderStr)) {
HTMLTextAreaElement buttonThis = (HTMLTextAreaElement) textareaNodeList.item(i);
buttonThis.setValue("lijian 00355334,");
}
}
}
}