javafx-webview加载网页实现模拟button、text、input、textarea、radio自动填充或者点击(通过非id去寻找指定的元素)

39 篇文章 0 订阅

通过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,");
                }
            }

        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaFXRadioButton是一种用户界面控件,用于在多个选项中选择一个选项。它通常与其他RadioButton组合在一起,形成一个单选按钮组。当用户选择其中一个RadioButton时,其他RadioButton自动取消选择。 JavaFXRadioButton具有以下特点: 1. 可以通过设置文本或图像来标识每个RadioButton。 2. 可以使用ToggleGroup将多个RadioButton组合在一起,确保它们之间是互斥的,即只能选择其中一个。 3. 可以通过设置选中状态来确定哪个RadioButton被选中。 4. 可以通过添加事件监听器来响应RadioButton的选择状态变化。 以下是一个简单的JavaFX RadioButton的示例代码: ```java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.RadioButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class RadioButtonExample extends Application { @Override public void start(Stage primaryStage) { RadioButton radioButton1 = new RadioButton("Option 1"); RadioButton radioButton2 = new RadioButton("Option 2"); RadioButton radioButton3 = new RadioButton("Option 3"); ToggleGroup toggleGroup = new ToggleGroup(); radioButton1.setToggleGroup(toggleGroup); radioButton2.setToggleGroup(toggleGroup); radioButton3.setToggleGroup(toggleGroup); VBox vbox = new VBox(radioButton1, radioButton2, radioButton3); Scene scene = new Scene(vbox, 200, 200); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` 这个示例创建了三个RadioButton,并将它们添加到一个垂直布局的VBox中。然后,通过ToggleGroup将它们组合在一起。最后,将VBox添加到场景中,并显示在舞台上。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值