com.gargoylesoftware.htmlunit.WebClient.waitForBackgroundJavaScript()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 JavaScript  
字(11.6k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中com.gargoylesoftware.htmlunit.WebClient.waitForBackgroundJavaScript()方法的一些代码示例,展示了WebClient.waitForBackgroundJavaScript()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.waitForBackgroundJavaScript()方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebClient
类名称:WebClient
方法名:waitForBackgroundJavaScript

WebClient.waitForBackgroundJavaScript介绍

[英]Experimental API: May be changed in next release and may not yet work perfectly!

This method blocks until all background JavaScript tasks have finished executing. Background JavaScript tasks are JavaScript tasks scheduled for execution via window.setTimeout, window.setInterval or asynchronous XMLHttpRequest.

If a job is scheduled to begin executing after (now + timeoutMillis), this method will wait for timeoutMillis milliseconds and then return a value greater than 0. This method will never block longer than timeoutMillis milliseconds.

Use this method instead of #waitForBackgroundJavaScriptStartingBefore(long) if you don't know when your background JavaScript is supposed to start executing, but you're fairly sure that you know how long it should take to finish executing.
[中]实验API:可能会在下一个版本中更改,可能还不能完美工作!
此方法会一直阻塞,直到所有后台JavaScript任务都完成执行。后台JavaScript任务是计划通过Windows执行的JavaScript任务。设定超时,窗口。setInterval或异步XMLHttpRequest。
如果作业计划在(现在+timeoutMillis)之后开始执行,此方法将等待timeoutMillis毫秒,然后返回大于0的值。此方法的阻止时间永远不会超过timeoutMillis毫秒。
如果你不知道背景JavaScript应该在什么时候开始执行,但是你很确定你知道需要多长时间才能完成,那么就用这个方法代替#waitForBackgroundJavaScriptStartingBefore(long)。

代码示例

代码示例来源:origin: mrdear/JavaWEB

HtmlPage tempPage = null;
try {
  webClient.waitForBackgroundJavaScript(500);
  tempPage = domElement.click();
  Thread.sleep(500);

代码示例来源:origin: stackoverflow.com

@Test
public void TestCall() throws FailingHttpStatusCodeException, MalformedURLException, IOException {      
  WebClient webClient = new WebClient(BrowserVersion.CHROME);
  webClient.getOptions().setUseInsecureSSL(true); //ignore ssl certificate
  webClient.getOptions().setThrowExceptionOnScriptError(false);
  webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
  String url = "https://www.wearvr.com/#game_id=game_4";
  HtmlPage myPage = webClient.getPage(url);
  webClient.waitForBackgroundJavaScriptStartingBefore(200);
  webClient.waitForBackgroundJavaScript(20000);
  //do stuff on page ex: myPage.getElementById("main")
  //myPage.asXml() <- tags and elements
  System.out.println(myPage.asText());

}

代码示例来源:origin: mrdear/JavaWEB

WebClientUtil() {
    webClient = new WebClient(BrowserVersion.CHROME);
    webClient.getOptions().setUseInsecureSSL(true);//支持https
    webClient.getOptions().setJavaScriptEnabled(true); // 启用JS解释器,默认为true
    webClient.getOptions().setCssEnabled(false); // 禁用css支持
    webClient.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时,是否抛出异常
    webClient.getOptions().setTimeout(10000); // 设置连接超时时间 ,这里是10S。如果为0,则无限期等待
    webClient.getOptions().setDoNotTrackEnabled(false);
    webClient.setJavaScriptTimeout(8000);//设置js运行超时时间
    webClient.waitForBackgroundJavaScript(500);//设置页面等待js响应时间,
  }
}

代码示例来源:origin: stackoverflow.com

@Test
public void TestCall() throws FailingHttpStatusCodeException, MalformedURLException, IOException {      
  WebClient webClient = new WebClient(BrowserVersion.CHROME);
  webClient.getOptions().setUseInsecureSSL(true); //ignore ssl certificate
  webClient.getOptions().setThrowExceptionOnScriptError(false);
  webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
  String url = "https://www.wearvr.com/#game_id=game_4";
  HtmlPage myPage = webClient.getPage(url);
  webClient.waitForBackgroundJavaScriptStartingBefore(200);
  webClient.waitForBackgroundJavaScript(20000);
  //do stuff on page ex: myPage.getElementById("main")
  //myPage.asXml() <- tags and elements
  System.out.println(myPage.asText());

}

代码示例来源:origin: com.atlassian.integrationtesting/atlassian-integrationtesting-lib

public int waitForAsyncEventsToComplete(long timeoutMillis)
{
  checkCurrentPage();
  return webClient.waitForBackgroundJavaScript(timeoutMillis);
}

代码示例来源:origin: stackoverflow.com

WebClient client = new WebClient;
HtmlPage page = client.getPage("http://www.exapmle.com"); 
client.waitForBackgroundJavaScript(5 * 1000);
Thread.sleep(10*1000);// this code will waite to 10 seconds
HtmlUnorderedList ul = (HtmlUnorderedList) page.getByXPath("//ul[contains(@class, 'class-name')]").get(0);
HtmlListItem li = (HtmlListItem) ul.getChildNodes().get(1); // I want to click li and get result page. But it takes a little time to execute.

li.click();

client.waitForBackgroundJavaScript(5 * 1000); 
// this code will waite to 10 seconds
Thread.sleep(10*1000);

代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-test

@Override
public void waitForAjax(WebDriver driver) {
  ((CustomizableHtmlUnitDriver) driver).getWebClient().waitForBackgroundJavaScript(30000);
}

代码示例来源:origin: org.juzu/juzu-core

public void waitForBackgroundJavaScript(long delay) {
  client.waitForBackgroundJavaScript(delay);
 }
}

代码示例来源:origin: juzu/juzu

public void waitForBackgroundJavaScript(long delay) {
  client.waitForBackgroundJavaScript(delay);
 }
}

代码示例来源:origin: stackoverflow.com

WebClient webClient = new WebClient(BrowserVersion.CHROME);\
HtmlPage page = webClient.getPage("http://link.com/");
webClient.waitForBackgroundJavaScript(3000);
DomElement el = page.getElementById("_eF");

代码示例来源:origin: stackoverflow.com

String strURL = "https://www.checkmytrip.com" ;
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);

try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_31)) {
  webClient.setAjaxController(new NicelyResynchronizingAjaxController());

  HtmlPage myPage = ((HtmlPage) webClient.getPage(strURL));
  webClient.waitForBackgroundJavaScript(10 * 1000);

  String theContent = myPage.asXml();
  System.out.println(theContent);
}

代码示例来源:origin: jenkinsci/jenkins-test-harness

/**
 * Wait for all async JavaScript tasks associated with the supplied {@link WebClient} instance
 * to complete.
 * @param webClient The {@link WebClient} instance.
 * @param timeout The timeout in milliseconds.                  
 */
public static void waitForJSExec(WebClient webClient, long timeout) {
  webClient.getJavaScriptEngine().processPostponedActions();
  webClient.waitForBackgroundJavaScript(timeout);
}

代码示例来源:origin: stackoverflow.com

try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
  webClient.getOptions().setThrowExceptionOnScriptError(false);
  final HtmlPage page = webClient.getPage("http://www.reuters.com/article/2015/07/08/us-alibaba-singapore-post-idUSKCN0PI03J20150708");
  webClient.waitForBackgroundJavaScript(10000);
  System.out.println(page.asText());
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws IOException {

  java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);

  WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45);
  String url = "https://www.kinoheld.de/kino-muenchen/royal-filmpalast/vorstellung/280823/?mode=widget&showID=280828#panel-seats";

  webClient.getOptions().setUseInsecureSSL(true);
  webClient.getOptions().setThrowExceptionOnScriptError(false);
  webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
  webClient.waitForBackgroundJavaScript(9000);
  HtmlPage response = webClient.getPage(url);

  System.out.println(response.getTitleText());
}

代码示例来源:origin: timurstrekalov/saga

@Override
protected void get(final URL fullUrl) {
  super.get(fullUrl);
  getWebClient().waitForBackgroundJavaScript(
      config != null ? config.getBackgroundJavaScriptTimeout() : Config.DEFAULT_BACKGROUND_JAVASCRIPT_TIMEOUT);
}

代码示例来源:origin: stackoverflow.com

WebClient webClient=new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.waitForBackgroundJavaScript(50000);

代码示例来源:origin: stackoverflow.com

try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
 new WebConnectionWrapper(webClient) {
   public WebResponse getResponse(WebRequest request) throws IOException {
     WebResponse response = super.getResponse(request);
     if (request.getUrl().toExternalForm().endsWith("identifier_select")) {
       String content = response.getContentAsString("UTF-8");
       content = content.replace(">$J( function()", "$J( function()");
       WebResponseData data = new WebResponseData(content.getBytes("UTF-8"),
           response.getStatusCode(), response.getStatusMessage(), response.getResponseHeaders());
       response = new WebResponse(data, request, response.getLoadTime());
     }
     return response;
   }
 };
 HtmlPage page = webClient.getPage("http://www.tf2outpost.com");
 HtmlAnchor a = page.getAnchorByHref("/login");
 page = a.click();
 page.<HtmlInput>getHtmlElementById("steamAccountName").setValueAttribute(username);
 page.<HtmlInput>getHtmlElementById("steamPassword").setValueAttribute(password);
 page = page.<HtmlInput>getHtmlElementById("imageLogin").click();
 webClient.waitForBackgroundJavaScript(5000);
 System.out.println(page.asXml());

代码示例来源:origin: stackoverflow.com

WebClient _webClient = new WebClient( BrowserVersion.FIREFOX_17 );
_webClient.getOptions().setUseInsecureSSL( true );
_webClient.getOptions().setThrowExceptionOnScriptError( false );
_webClient.getOptions().setRedirectEnabled( true );

var page = (HtmlPage)_webClient.getPage( "https://play.google.com/apps/publish/v2/" );

HtmlInput emailElement = (HtmlTextInput)page.getElementById( "Email" );
emailElement.type( Settings.Default.Login );

HtmlInput passwordElement = (HtmlInput)page.getElementById( "Passwd" );
passwordElement.type( Settings.Default.Password );

HtmlSubmitInput signInLink = (HtmlSubmitInput)page.getElementById( "signIn" );
HtmlPage page2 = (HtmlPage)signInLink.click();

_webClient.waitForBackgroundJavaScript( 2000 );

var installsNode = ( from p in page2.getElementsByTagName( "p" ).toArray().Cast<HtmlParagraph>()
           let data_column = p.getAttribute( "data-column" )
       where data_column != null && "INSTALLS".Equals( data_column, StringComparison.OrdinalIgnoreCase )
       select p ).FirstOrDefault();

代码示例来源:origin: stackoverflow.com

final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17,
       YOUR_PROXY_HOST, YOUR_PROXY_PORT);
   WebRequest request = new WebRequest(
       new URL(
           "http://bitcoincharts.com/charts/btceUSD#rg60ztgSzm1g10zm2g25zv"));
   webClient.getOptions().setThrowExceptionOnScriptError(false);
   webClient.setJavaScriptTimeout(10000);
   webClient.getOptions().setJavaScriptEnabled(true);
   webClient.setAjaxController(new NicelyResynchronizingAjaxController());
   webClient.getOptions().setTimeout(10000);
   HtmlPage page = webClient.getPage(request);
   webClient.waitForBackgroundJavaScript(30000);
   List<HtmlAnchor> anchors1 = page.getAnchors();
   HtmlAnchor link2 = null;
   for (HtmlAnchor anchor : anchors1) {
     //System.out.println(anchor.asText());
     if (anchor.asText().indexOf("Load raw data") > -1) {
       link2 = anchor;
       break;
     }
   }
   page = link2.click();

代码示例来源:origin: stackoverflow.com

final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);

webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setCssErrorHandler(new SilentCssErrorHandler());

webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setAppletEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setPopupBlockerEnabled(true);
webClient.getOptions().setTimeout(10000);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
webClient.getOptions().setThrowExceptionOnScriptError(true);
webClient.getOptions().setPrintContentOnFailingStatusCode(true);
webClient.waitForBackgroundJavaScript(5000);

try {
  HtmlPage page = webClient.getPage(URL);
  System.out.println(page.asText());
} catch (Exception e) {
  e.printStackTrace();
}
webClient.closeAllWindows();

相关文章

微信公众号

WebClient类方法