N
N
nemnogodanil2020-01-03 17:02:30
Java
nemnogodanil, 2020-01-03 17:02:30

When you click on the website button, nothing happens. html unit java?

I have a program, it connects to the site, enters the login and password into the input fields, then it must click on the button and submit the form data, so that it can then sit on the site under its own name. Everything works and starts, the fields are filled, but the site page is not updated when you click on the login button. It finds all fields and the button correctly. My code:

java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
            java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
            printLn("Connection...");
            WebClient client = new WebClient(BrowserVersion.CHROME);
            client.getOptions().setUseInsecureSSL(true);
            client.getOptions().setCssEnabled(false);
            client.getOptions().setJavaScriptEnabled(true);
            client.getOptions().setThrowExceptionOnScriptError(false);
            client.getOptions().setThrowExceptionOnFailingStatusCode(false);
            HtmlPage page = client.getPage("path");
            HtmlForm form = page.getFirstByXPath("/html/body/div[2]/div[2]/div/div/div[1]/form");
            final HtmlTextInput textField =  form.getFirstByXPath("/html/body/div[2]/div[2]/div/div/div[1]/form/div[1]/div/dl[1]/dd/input" );
            textField.setValueAttribute("login");
            final HtmlPasswordInput pwd =  form.getFirstByXPath("/html/body/div[2]/div[2]/div/div/div[1]/form/div[1]/div/dl[2]/dd/input[1]");
            pwd.removeAttribute("disabled");
            pwd.setValueAttribute("password");
            final HtmlButton btn = form.getFirstByXPath("/html/body/div[2]/div[2]/div/div/div[1]/form/div[1]/div/div[4]/div[2]/button");
            btn.click();
            client.waitForBackgroundJavaScriptStartingBefore(200);
            client.waitForBackgroundJavaScript(20000);
            printLn(page.getBody().asText());
            client.addWebWindowListener( new WebWindowListener() {
                public void webWindowOpened(WebWindowEvent webWindowEvent) { }
                public void webWindowContentChanged(WebWindowEvent event) {
                    printLn(page.getUrl().toString());
                    printLn(page.getBody().asText());
                }
                public void webWindowClosed(WebWindowEvent webWindowEvent) { }
            });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VictorZZZZ, 2021-01-07
@VictorZZZZ

And you try to send the form not through btn.click()but throughform.submit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question