Hey guys, So Im trying to make a program using the HTML Unit library that will login to a site with my login info, and then go to another page of the site and post data to that page. My code, is getting null pointer exceptions, as if the form that Im trying to access does not exist. Here is the code to better understand:
This is the code without the gui, as you dont need the gui, but the gui is in the same class. Running this code returns "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionprivate void HitActionPerformed(java.awt.event.ActionEvent evt) { try { String IP; String Port; String Time; IP=Host.getText(); Port=PortField.getText(); Time=TimeField.getText(); final WebClient webClient = new WebClient(); //This part of the code logs in to the site, it works fine as I get no errors on it final HtmlPage page1 = webClient.getPage("http://atomicbooter.org/"); webClient.getCookieManager().setCookiesEnabled(true); final HtmlForm form = page1.getFirstByXPath("//form[@action='set_state.php?action=login']"); final HtmlSubmitInput button = form.getFirstByXPath("/html/body/div/div[4]/form/table/tbody/tr[3]/td[2]/input"); final HtmlTextInput textField = form.getInputByName("username"); final HtmlPasswordInput Pass = form.getInputByName("password"); textField.setValueAttribute("Seegee"); Pass.setValueAttribute("PASSWORD"); final HtmlPage page2 = button.click(); //This part of the code goes to the next page that I want. final HtmlPage page3 = webClient.getPage("http://atomicbooter.org/hub.php"); final HtmlForm form2 = page3.getFirstByXPath("/html/body/div/div[6]/form"); final HtmlSubmitInput button2 = form.getFirstByXPath("/html/body/div/div[6]/form/table/tbody/tr[6]/td/input"); final HtmlTextInput textField2 = form.getFirstByXPath("//*[@id=host]"); final HtmlTextInput tme = form.getFirstByXPath("/html/body/div/div[6]/form/table/tbody/tr[4]/td[2]/input"); final HtmlTextInput prt = form.getFirstByXPath("//*[@id=port]"); final HtmlTextInput pwr = form.getFirstByXPath("/html/body/div/div[6]/form/table/tbody/tr[5]/td[2]/input"); textField.setValueAttribute(IP); tme.setValueAttribute(Time); // THIS IS LINE 194!!!!!!! WHERE I GET NULL POINTER EXCEPTION! prt.setValueAttribute(Port); pwr.setValueAttribute("100"); final HtmlPage page4 = button.click(); } catch (IOException ex) { Logger.getLogger(Master.class.getName()).log(Level.SEVERE, null, ex); } }
at Master.HitActionPerformed(Master.java:194)"
The object does exist. Here is the html source code of the second page of the site (The page that I get the error on) for you to see:
It would be great if someone could help. Thanks in advance!HTML Code:<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <head> <title>Atomic Booter</title> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> <meta name='robots' content='noindex,nofollow'> <link rel='stylesheet' type='text/css' href='css/blue.css' /> </head> <body> <div id='container'> <div id='logo'> <a href='index.php' title='Home'><img src='images/atomic.png' alt='Atomic Booter' /></a> </div> <div id='login'> Welcome, <a href='profile.php?id=31' title='View My Profile'>seegee</a>!<br /> </div> <div class='br'></div> <div id='navlist'> <ul> <li><a href='index.php' title='Home'>Home</a></li> <li><a href='hub.php' title='Boot' class='active'>Boot</a></li> <li><a href='converter.php' title='Host -> IP'>Host -> IP</a></li> <li><a href='ip_logger.php' title='IP Logger'>IP Logger</a></li> <li><a href='friends.php' title='Friends'>Friends</a></li> <li><a href='enemies.php' title='Enemies'>Enemies</a></li> <li><a href='attacks.php' title='My Attacks'>My Attacks</a></li> <li><br /></li> <li><a href='profile.php?id=31' title='View Profile'>View Profile</a></li> <li><a href='edit_profile.php' title='Edit Profile'>Edit Profile</a></li> <li><a href='messages.php' title='Messages'>Messages</a></li> <li><a href='statistics.php' title='Statistics'>Statistics</a></li> <li><a href='set_state.php?action=logout' title='Logout'>Logout</a></li> </ul> </div> <div class='content'> <h3>Statistics</h3> <form> <table cellpadding='5' cellspacing='5' style='text-align: left;'> <tr> <td style='width: 60%; text-align: right;'>Server Count:</td> <td>2</td> </tr> <tr> <td style='text-align: right;'>Allocated Servers:</td> <td>2</td> </tr> <tr> <td style='text-align: right;'>Booter Version:</td> <td>1.1</td> </tr> </table> </form> </div> <div class='content'> <h3>DDoS Attack</h3> <form name='booter' action='' method='post'> <center> Use the form below to initiate an attack:</center><br /> <table cellpadding='5' cellspacing='5' style='text-align: left;'> <tr> <td style='text-align: right;' valign='middle'>Flood Type</td> <td> UDP And SYN</td> </tr> <tr> <td style='text-align: right;'>Target</td> <td width='50%'><input type='text' name='host' id='host' size='30' value='' /></td> </tr> <tr> <td style='text-align: right;'>Port (0 For Random)</td> <td width='50%'><input size='5' name='port' type='text' id='port' value='80'></td> </tr> <tr> <td style='text-align: right;' valign='middle'>Time:</td> <td><input type='text' name='time' size='2' value='35' /> seconds</td> </tr> <tr> <td style='text-align: right;' valign='middle'>Power:</td> <td><input type='text' name='power' size='2' value='50' /> %</td> </tr> <tr> <td colspan='2' valign='right' style='text-align: right;'><input type='submit' name='boot' class='button' value='Flood' /></td> </tr> </table> </form> </div> <div class='br'></div> <div id='footer'> <p class='center' style='border: 1px solid #ccc; background: #111; padding: 5px; margin-bottom: 15px;'> <b>Online Users:</b><br /><br /> <span style='font-size: 10px;'> <a href='profile.php?id=31' title='View Profile'>seegee</a>, <a href='profile.php?id=30' title='View Profile'>neilvip1</a>, <a href='profile.php?id=42' title='View Profile'>Majin</a>, <a href='profile.php?id=116' title='View Profile'>Judahmang</a>, <a href='profile.php?id=56' title='View Profile'>xjoshgx</a>, <a href='profile.php?id=50' title='View Profile'>Citizen</a></span> </p> <p class='center'> Copyright © Atomic Booter<br /> <a href='tos.php' title='Terms Of Service' target='_blank'>Terms Of Service</a> </p> </div> </div> </body> </html>