Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

HTML-Unit Website Manipulation

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm back at trying to get HTMLUnit working and I was able to implement it into the project but I'm having some difficulties with it.. I want to track a package via DHL's website and it gives me an error in the console. The whole purpose is for the program to insert the DHL tracking number in the tracking text box, and then for the program to "click" the search button and get the tracking results. I am aware of DHL's API, but this is a school project and I'm trying to learn how to do something like this.

Here is my current code:

This is the error I get in the console:

Apr 23, 2015 7:55:49 PM com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement addbehavior
WARNING: Unimplemented behavior: #default#userdata
Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[*] attributeName=[name] attributeValue=[sbtc]
at com.gargoylesoftware.htmlunit.html.HtmlPage.getElementByName(HtmlPage.java:1747)
at htmlTest.main(htmlTest.java:17)


Any insight will be greatly appreciated!
 
Sheriff
Posts: 14758
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look more closely at the page source, the textarea for entering tracking numbers on that page has a name of "AWB" and an id of "AWB_crossrefpar1_taskcenter_taskcentertabs_item1229046233349_par_expandablelink_insideparsys_fasttrack".

And if you study the horrific JavaScript code on that page, you'll see that they are using document.getElementById(), not getElementByName()

It's horrific JavaScript code because there's a lot of copy-paste programming going on there.
 
Marshal
Posts: 67463
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have broken the long lines in your post. Please note how to do it.
This is not a “beginning” topic, so I shall move it.
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!