Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript component not rendered #335

Open
magick93 opened this issue Nov 3, 2018 · 1 comment
Open

Javascript component not rendered #335

magick93 opened this issue Nov 3, 2018 · 1 comment

Comments

@magick93
Copy link

magick93 commented Nov 3, 2018

Hello,

I am using the below code in an attempt to render, correctly, the following url:

ttps://www.tradingview.com/chart/USDCNH/fxN4XIA0-USD-CNH-Sell-Idea/

However, the chart never renders.

Any ideas as to what is wrong?

Code



import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.ErrorHandler;
import org.openqa.selenium.remote.RemoteWebDriver;

import com.machinepublishers.jbrowserdriver.JBrowserDriver;
import com.machinepublishers.jbrowserdriver.Settings;
import com.machinepublishers.jbrowserdriver.Timezone;
import com.machinepublishers.jbrowserdriver.UserAgent;

public class Example {
  public static void main(String[] args) throws MalformedURLException {
  
	File userDataDirectory = FileUtils.getTempDirectory();
		// You can optionally pass a Settings object here,
	    // constructed using Settings.Builder
	    JBrowserDriver driver = new JBrowserDriver(Settings.builder()
	    		.ajaxResourceTimeout(100000)
	            .ajaxWait(100000)
	            .headless(false)
	            .csrf()
	            .logJavascript(true)
	            .loggerLevel(Level.ALL)
	            .userAgent(UserAgent.CHROME)
	            .userDataDirectory(userDataDirectory )
	            .timezone(Timezone.AMERICA_NEWYORK)
	            .build());

	    // This will block for the page load and any
	    // associated AJAX requests
	    driver.get("https://www.tradingview.com/chart/USDCNH/fxN4XIA0-USD-CNH-Sell-Idea/");

	    System.out.println(driver.getCapabilities());
	    
	    // You can get status code unlike other Selenium drivers.
	    // It blocks for AJAX requests and page loads after clicks 
	    // and keyboard events.
	    //System.out.println(driver.getStatusCode());

	    // Returns the page source in its current state, including
	    // any DOM updates that occurred after page load
	    String pageSource = driver.getPageSource();
		//System.out.println(pageSource);
		
		Document doc = Jsoup.parse(pageSource);
		
		Element masthead = doc.select(".tv-chart-view__symbol-link").first();
		
		//System.out.println(masthead);
		
		String text = doc.select(".tv-chart-view").html(); // .attr("data-options") "An example link"
		//js-chart-view
		//String linkHref = link.attr("href"); // "http://example.com/"
		
		String unescapeHtml = StringEscapeUtils.unescapeHtml(text);
		
		//System.out.println(pageSource);

		
		//tv-chart-view__symbol-link
	    
	    // Close the browser. Allows this thread to terminate.
	    driver.quit();
	    System.out.println("finished");
  }
}
@leemgk
Copy link

leemgk commented Dec 22, 2018

JBrowserDriver driver = new JBrowserDriver(Settings.builder()
.ajaxResourceTimeout(100000)
.ajaxWait(100000)
.headless(false)
.csrf()
.logJavascript(true)
.loggerLevel(Level.ALL)
.userAgent(UserAgent.CHROME)
.userDataDirectory(userDataDirectory )
.timezone(Timezone.AMERICA_NEWYORK)
JBrowserDriver driver = new JBrowserDriver(Settings.builder()
.ajaxResourceTimeout(100000)
.ajaxWait(100000)
.headless(false)
.csrf()
.logJavascript(true)
.loggerLevel(Level.ALL)
.userAgent(UserAgent.CHROME)
.userDataDirectory(userDataDirectory )
.timezone(Timezone.AMERICA_NEWYORK)
.headScript("")// enable canvas rendering
.build());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants