Question

I am trying to pull a value from a website using HTMLUnit and Xpath. I have successfully created the xpath to pull the value from the right location but I cannot get it to pull the dynamic web content. Instead it will continue to pull the value that is found when you pull the 'View web site source' up in the browser. I am completely unsure why it refuses to pull the dynamic data and am needing some help in this regard.

In short, I continue to get the value "Player 1" rather than the the randomly generated character name that appears on the screen.

This is my xpath:

DomText domRedFighter = page.getFirstByXPath("//div[@class='left']/span/text()");

This is what the xpath is pulling from:

<span id="p1name" class="redtext">Player 1</span><br/><br/>

This is what I want the xpath to pull from:

<span id="p1name" class="redtext">Insert Dynamic Name Here</span><br/><br/>

Any help will be welcome. :)

Was it helpful?

Solution

I figured it out.

It turns out that, even though the web site showed the correct name at first, the default HTML was 'Player 1.' It would stay as Player 1 until an AJAX command would change it. So I just have to monitor for changes in the HTML code. FYI, I am building a betting bot for Salty Bets if this information would be useful to you. I have also switch over to Selenium instead of HTMLUnit. It seems to be a very noob-friendly program compared to HTMLUnit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top