0

I wanted to execute an Anchor using .click() method by getting the Anchor using getAnchorByHref that contains javascript code to go to another page. Here's my snippet below. But running this code gives me.

ElementNotFoundException: elementName=[a] attributeName=[href] attributeValue=[javascript:submit('ActivityForm.jsp')]

try{

   HtmlPage currentPage = client.getWebClient().getPage("url");
   HtmlAnchor createOrder = (HtmlAnchor) currentPage.getAnchorByHref("javascript:submit('ActivityForm.jsp')");
   createOrder.click();

}
catch(FailingHttpStatusCodeException | IOException e){
        e.printStackTrace();
}
1
  • 1
    Can you pls post the html code of the anchor tag also Commented Oct 20, 2017 at 13:29

1 Answer 1

1

As the ElementNotFoundException says: the element you are looking for was not found on the page. There might be various reasons for that

  • there is no anchor element with this javascipt (comparison is done using equals so his is case sensitive and white space sensitive)
  • the element was added after the page loading by some javascript. In this case you have to wait for the javascripts jobs after getting the page and before start searching for the anchor
  • maybe there is an error in HtmlUnit

If you provide a public url we can have a look at your case.

Sign up to request clarification or add additional context in comments.

1 Comment

My guess is that one of the first two is the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.