0

I need to use below code to login to webpage using Java

Cannot resolve symbol 'HtmlPage'

error with below code

final WebClient webClient = new WebClient();
        final HtmlPage page1 = webClient.getPage("https://www.valueresearchonline.com/login");

        final HtmlTextInput textField = form.getInputByName("email");
        textField.setValueAttribute("jon@jon.com");

For WebClient added below dependancy in pom.xml

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
            <version>5.3.22</version>
        </dependency>

But not getting what other dependancies to be added for HtmlPage ?

vikramvi
  • 3,312
  • 10
  • 45
  • 68

1 Answers1

0

I think you got the wrong depency. You need:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.64.0</version>
</dependency>

You also should remove webflux and potentially generated imports.

DrHopfen
  • 752
  • 3
  • 13
  • you mean "htmlunit" is only thing needed for both WebClient & HtmlPage ? – vikramvi Sep 01 '22 at 10:52
  • net.sourceforge.htmlunit:htmlunit:pom:2.64.0 failed to transfer from https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact net.sourceforge.htmlunit:htmlunit:pom:2.64.0 from/to central (https://repo.maven.apache.org/maven2): transfer failed for https://repo.maven.apache.org/maven2/net/sourceforge/htmlunit/htmlunit/2.64.0/htmlunit-2.64.0.pom – vikramvi Sep 01 '22 at 11:03
  • solved above problem with help of https://stackoverflow.com/questions/5074063/maven-error-failure-to-transfer – vikramvi Sep 01 '22 at 11:13