繁体   English   中英

如果按钮在另一个div中,如何单击htmlUnit

[英]howmake a click on htmlUnit if the button is in another div

单击后无法获得响应,我尝试了很多示例,但未成功。

我认为这是该网站的javascript的问题,因为在示例中,我尝试了其简单的点击操作。

但是,这是我无法点击的按钮

<div class="frame-login">
                <div class="frame-cargando" ng-show="cargandoLogin">
                    <div class="cargando cargando-login"></div>
                </div>
                <div class="formulario {{cargandoLogin ? 'formulario-deshabilitado' : ''}}" ng-show="!autentificando">
                    <form name="security_check" id="security">
                        <input type="text" name="j_username" id="j_username"
                            ng-model="nombreUsuario"
                            placeholder="{{ 'INPUT.LOGIN.USUARIO' | translate }}"
                            autocomplete="off" maxlength="30" />
                        <input type="password"
                            name="j_password" id="j_password" ng-model="clave"
                            placeholder="{{ 'INPUT.LOGIN.CONTRASENA' | translate }}"
                            maxlength="30" autocomplete="off" />
                    </form>
                </div>
                <div ng-show="autentificando" class="{{cargandoLogin ? 'formulario-deshabilitado' : ''}}">
                    <h2 class="h2-supervisor">{{ 'TITULO.HOLA' | translate }} {{usuario.nombre}} {{usuario.apellido}}</h2>
                    <h3 class="h3-supervisor">{{ 'SELECCIONAR.SUPERVISOR' | translate}}</h3>
                    <select ng-model="usuario.supervisor" class="combo-supervisor" ng-change="validarFormulario()" ng-disabled="!activarBoton"
                        ng-options="option.nombreUsuario as option.nombreUsuario for option in supervisores">
                        <option value="">{{ 'COMBOBOX.SELECCIONE' | translate }}</option>
                    </select>
                </div>
                <button class="boton-login" ng-click="validarFormulario()" ng-show="!autentificando" ng-disabled="!activarBoton">{{ 'BOTON.INGRESAR' | translate }}</button>
                <div class="errorl-login">{{ mensaje }}</div>
            </div>

单击的答案是相同的站点,但我在j_username和j_password中输入了值。

我正在Java 8中尝试,我的代码是:

HtmlPage page = webClient.getPage("https://piv.wom.cl/Dashboardweb/#/seccion6/");
HtmlForm form = page.getFormByName("security_check");
HtmlTextInput nameField = form.getInputByName("j_username");
nameField.setValueAttribute("user");
HtmlPasswordInput passField = form.getInputByName("j_password");
passField.setValueAttribute("pass");
HtmlButton button = (HtmlButton) page.getElementsByTagName("button").get(0);
HtmlPage page2 = button.click();

if( page2 != null){
  System.out.println("we did It=[" + page2.asXml() + "]");
}

编辑1:我尝试通过另一种方式获取页面,将值从get传递如下:

 HtmlPage page = webClient.getPage("https://piv.wom.cl/Dashboard-web/login/j_security_check?j_username=username&j_password=password");

但是现在,java显示此错误:

Four
======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.JavaScriptException]
com.gargoylesoftware.htmlunit.ScriptException: Error: [$rootScope:infdig] http://errors.angularjs.org/1.4.5/$rootScope/infdig?p0=10&p1=%5B%5D (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js#133)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:918)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:532)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:847)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:819)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2520)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2513)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:264)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:330)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.fireEvent(EventTarget.java:189)
    at com.gargoylesoftware.htmlunit.html.DomElement$2.run(DomElement.java:1413)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:532)
    at com.gargoylesoftware.htmlunit.html.DomElement.fireEvent(DomElement.java:1418)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1220)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:259)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:536)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:398)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:463)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448)
    at main.Test.main(Test.java:31)
Caused by: net.sourceforge.htmlunit.corejs.javascript.JavaScriptException: Error: [$rootScope:infdig] http://errors.angularjs.org/1.4.5/$rootScope/infdig?p0=10&p1=%5B%5D (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js#133)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1119)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:911)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:422)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:331)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3570)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:840)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:903)
    ... 21 more
JavaScriptException value = Error: [$rootScope:infdig] http://errors.angularjs.org/1.4.5/$rootScope/infdig?p0=10&p1=%5B%5D
== CALLING JAVASCRIPT ==

如果要在上述“ div”中提交表单,则可以使用Java脚本函数,例如:document.getElementById(“ form id”)。submit()。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM