1

How can I click on a link in an HTML table using Jsoup and load the document. I was able to obtain the href but it's not properly formatted so i can't load the page.

Element table = doc.select("table.dxgvTable_Office2010Blue");
Elements l = table.select("a");
for(Element links : l){
    System.out.println(links.text() + "\t" + links.attr("href"));
}

Below is the html code for every row in the table

</tr><tr id="ctl00_pageMain_dataGrid_DXDataRow8" class="dxgvDataRow_Office2010Blue">
                        <td class="dxgv"><a class="dxeHyperlink_Office2010Blue" href="javascript:focusedRowField.Set(&#39;row&#39;, dataGridClient.GetRowKey(dataGridClient.GetFocusedRowIndex())); drilldown_button.DoClick();">Canadian Short Term Fixed Income</a></td><td class="dxgv" align="right">47,591</td><td class="dxgv" align="right">4.21 %</td><td class="dxgv" align="right">260.2</td><td class="dxgv" align="right">0.55%</td><td class="dxgv" align="right">2,154.9</td><td class="dxgv" align="right">44,970</td><td class="dxgv" align="right">4.79%</td><td class="dxgvHEC"></td>

How do I click on the Link 'Canadian Short Term Fixed Income' if the output below is what is saved in href?

javascript:focusedRowField.Set('row',
    dataGridClient.GetRowKey(dataGridClient.GetFocusedRowIndex()));  
drilldown_button.DoClick();

How can i perform the click on the url using Java?

Bob Ezuba
  • 510
  • 1
  • 5
  • 22

1 Answers1

1

You can't click on a button with JSoup. JSoup is a parser to extract/manipulate the information but you can't trigger an action and have the associated javascript executed.

One easy way to achieve that would be to use a tool to automate a real browser, something like Selenium.

Community
  • 1
  • 1
RealHowTo
  • 34,977
  • 11
  • 70
  • 85