Skip to content

Not able to get HTMLElement #81

@fusion2013

Description

@fusion2013

Hello,

I am using Htmlunit 2.36.0. version.

I want to get table data below is the code, but not able to get it, but that data is showing on the browser, here is my code:-

public static void main(String[] args) {

	String baseUrl = "https://www.pgatour.com/competition/2017/safeway-open/leaderboard.html" ;
	WebClient client = new WebClient(BrowserVersion.CHROME);		
	
	client.getOptions().setCssEnabled(false);
	client.getOptions().setUseInsecureSSL(true);
	client.getOptions().setJavaScriptEnabled(true);
	client.getOptions().setThrowExceptionOnScriptError(false);
	 
	try {
		
		
		HtmlPage page = client.getPage(baseUrl);		
		client.waitForBackgroundJavaScriptStartingBefore(100000);
	
		List<Object> playerNames = (List<Object>) page.getByXPath("//div[@class='player-name-col']");
		if(playerNames.isEmpty()) {
			LOG.info("No Players Found...");
		} else {
			for(Object obj : playerNames) {				
				HtmlElement playerName = (HtmlElement) obj;
				LOG.info(playerName.asText());
			}
				
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		client.close();
	}
}

Can you please help me why I am not able to get the table.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions