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

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

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

WebClientOptions.setJavaScriptEnabled介绍

[英]Enables/disables JavaScript support. By default, this property is enabled.
[中]启用/禁用JavaScript支持。默认情况下,此属性处于启用状态。

代码示例

代码示例来源: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: com.atlassian.integrationtesting/atlassian-integrationtesting-lib

public void setJavaScriptEnabled(boolean enabled)
  {
    webClient.getOptions().setJavaScriptEnabled(enabled);
  }
}

代码示例来源:origin: net.sourceforge.jwebunit/jwebunit-htmlunit-plugin

/**
 * @see net.sourceforge.jwebunit.api.IJWebUnitDialog#setScriptingEnabled(boolean)
 */
@Override
public void setScriptingEnabled(boolean value) {
 // This variable is used to set Javascript before wc is instancied
 jsEnabled = value;
 if (wc != null) {
  wc.getOptions().setJavaScriptEnabled(value);
 }
}

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

/**
 * Enables/disables JavaScript support.
 * Short-hand method to ease discovery of feature + improve readability
 *
 * @param enabled {@code true} to enable JavaScript support
 * @see WebClientOptions#setJavaScriptEnabled(boolean)
 * @since 2.0
 */
public void setJavaScriptEnabled(boolean enabled) {
  getOptions().setJavaScriptEnabled(enabled);
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver

public void setJavascriptEnabled(boolean enableJavascript) {
 this.enableJavascript = enableJavascript;
 getWebClient().getOptions().setJavaScriptEnabled(enableJavascript);
}

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

public boolean setJavascriptEnabled(boolean b) {
  boolean p = getOptions().isJavaScriptEnabled();
  if (useJS)
    this.getOptions().setJavaScriptEnabled(b);
  return p;
}

代码示例来源:origin: com.github.albfernandez.richfaces/richfaces-build-resources

public void checkComponentSource(URL pageName, String xmlunitPage, By pageElementToTest) throws IOException, SAXException {
  WebClient client = new WebClient();
  client.getOptions().setJavaScriptEnabled(false);
  HtmlPage page = client.getPage(pageName);
  DomElement element;
  String locator = pageElementToTest.toString();
  locator = locator.substring(locator.indexOf(':') + 1).trim();
  if (pageElementToTest instanceof ById) {
    element = page.getElementById(locator);
  } else if (pageElementToTest instanceof ByTagName) {
    element = page.getElementsByTagName(locator).get(0);
  } else {
    throw new IllegalArgumentException("Only id and name are supported");
  }
  String pageCode = element.asXml();
  checkXmlStructure(xmlunitPage, pageCode);
}

代码示例来源:origin: org.apache.camel/camel-linkedin-api

final WebClientOptions options = webClient.getOptions();
options.setRedirectEnabled(true);
options.setJavaScriptEnabled(false);
options.setThrowExceptionOnFailingStatusCode(true);
options.setThrowExceptionOnScriptError(true);

代码示例来源:origin: ksahin/introWebScraping

WebClient client = new WebClient();
client.getOptions().setCssEnabled(false);
client.getOptions().setJavaScriptEnabled(false);
try {
  String searchUrl = baseUrl + "search/sss?sort=rel&query=" + URLEncoder.encode(searchQuery, "UTF-8");

代码示例来源:origin: com.epam.gepard/gepard-rest

/**
 * Constructor of the Jira Site Handler object.
 *
 * @param tc          is the caller test case
 * @param environment provide the Environment object of Gepard, it must contain connectivity info to JIRA.
 */
public JiraSiteHandler(final GepardTestClass tc, final Environment environment) {
  this.environment = environment;
  webClient = new WebClient();
  webClient.getOptions().setJavaScriptEnabled(false);
  webClient.getOptions().setThrowExceptionOnScriptError(false);
  webClient.getOptions().setUseInsecureSSL(true);
  String phrase = Base64.encode((environment.getProperty(Environment.JIRA_SITE_USERNAME) + ":" + environment.getProperty(Environment.JIRA_SITE_PASSWORD)).getBytes());
  webClient.addRequestHeader("Authorization", "Basic " + phrase);
  try {
    JSONObject serverInfo = getJiraServerInfo();
    String serverTitle = serverInfo.get("serverTitle").toString();
    String version = serverInfo.get("version").toString();
    tc.logComment("Connected to JIRA Server: \"" + serverTitle + "\", version: " + version);
  } catch (FailingHttpStatusCodeException | IOException | JSONException e) {
    throw new SimpleGepardException("Cannot connect to JIRA properly, pls check the settings, reason: " + e.getMessage(), e);
  }
}

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

this.getOptions().setJavaScriptEnabled(useJS);
this.getOptions().setCssEnabled(false);//if you don't need css

代码示例来源:origin: ArcBees/GWTP

webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setRedirectEnabled(true);

代码示例来源:origin: com.gwtplatform/gwtp-crawler-service

webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setRedirectEnabled(true);

代码示例来源:origin: USCDataScience/sparkler

@Override
public void init(JobContext context, String pluginId) throws SparklerException {
  super.init(context, pluginId);
  //TODO: get timeouts from configurations
  driver = new WebClient(BrowserVersion.BEST_SUPPORTED);
  driver.setJavaScriptTimeout(DEFAULT_JS_TIMEOUT);
  WebClientOptions options = driver.getOptions();
  options.setCssEnabled(false);
  options.setAppletEnabled(false);
  options.setDownloadImages(false);
  options.setJavaScriptEnabled(true);
  options.setTimeout(DEFAULT_TIMEOUT);
  options.setUseInsecureSSL(true);
  options.setPopupBlockerEnabled(true);
  options.setDoNotTrackEnabled(true);
  options.setGeolocationEnabled(false);
  options.setHistorySizeLimit(2);
  options.setPrintContentOnFailingStatusCode(false);
  options.setThrowExceptionOnScriptError(false);
  options.setThrowExceptionOnFailingStatusCode(false);
  if (this.httpHeaders != null && !this.httpHeaders.isEmpty()) {
    LOG.info("Found {} headers", this.httpHeaders.size());
    this.httpHeaders.forEach((name, val) -> driver.addRequestHeader(name, val));
  } else {
    LOG.info("No user headers found");
  }
}

代码示例来源:origin: com.axway.ats.framework/ats-uiengine

webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(true);
webClient.getOptions().setPrintContentOnFailingStatusCode(true);

代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver

private WebClient createWebClient(BrowserVersion version) {
 WebClient client = newWebClient(version);
 WebClientOptions options = client.getOptions();
 options.setHomePage(WebClient.URL_ABOUT_BLANK.toString());
 options.setThrowExceptionOnFailingStatusCode(false);
 options.setPrintContentOnFailingStatusCode(false);
 options.setJavaScriptEnabled(enableJavascript);
 options.setRedirectEnabled(true);
 options.setUseInsecureSSL(true);
 // Ensure that we've set the proxy if necessary
 if (proxyConfig != null) {
  options.setProxyConfig(proxyConfig);
 }
 client.setRefreshHandler(new WaitingRefreshHandler());
 return modifyWebClient(client);
}

代码示例来源:origin: xuxueli/xxl-crawler

webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);

代码示例来源:origin: com.synaptix.redpepper/redpepper-automation

@Override
  protected WebClient modifyWebClient(WebClient client) {
    myClient = client;
    client.getCookieManager().setCookiesEnabled(true);
    client.getOptions().setJavaScriptEnabled(true);
    client.getOptions().setCssEnabled(true);
    client.getOptions().setPopupBlockerEnabled(false);
    client.setIncorrectnessListener(new SilentIncorrectnessListener());
    client.setCssErrorHandler(new QuietCssErrorHandler());
    client.setAjaxController(new NicelyResynchronizingAjaxController());
    return client;
  }
}

代码示例来源:origin: ksahin/introWebScraping

public static WebClient autoLogin(String loginUrl, String login, String password) throws FailingHttpStatusCodeException, MalformedURLException, IOException{
  WebClient client = new WebClient();
  client.getOptions().setCssEnabled(false);
  client.getOptions().setJavaScriptEnabled(false);
  
  HtmlPage page = client.getPage(loginUrl);
  
  HtmlInput inputPassword = page.getFirstByXPath("//input[@type='password']");
  //The first preceding input that is not hidden
  HtmlInput inputLogin = inputPassword.getFirstByXPath(".//preceding::input[not(@type='hidden')]");
  
  inputLogin.setValueAttribute(login);
  inputPassword.setValueAttribute(password);
  
  //get the enclosing form
  HtmlForm loginForm = inputPassword.getEnclosingForm() ;
  
  //submit the form
  page = client.getPage(loginForm.getWebRequest(null));
  
  //returns the cookies filled client :)
  return client;
}

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

public static WebClient newInstance(final BrowserVersion version) {
  final WebClient client = new WebClient(version) {
    @Override
    public WebResponse loadWebResponse(final WebRequest webRequest) throws IOException {
      return new WebResponseProxy(super.loadWebResponse(webRequest));
    }
  };
  client.setIncorrectnessListener(quietIncorrectnessListener);
  client.setJavaScriptErrorListener(loggingJsErrorListener);
  client.setHTMLParserListener(quietHtmlParserListener);
  client.setCssErrorHandler(quietCssErrorHandler);
  client.getOptions().setJavaScriptEnabled(true);
  client.setAjaxController(new NicelyResynchronizingAjaxController());
  client.getOptions().setThrowExceptionOnScriptError(false);
  client.getOptions().setThrowExceptionOnFailingStatusCode(false);
  client.getOptions().setPrintContentOnFailingStatusCode(false);
  client.setWebConnection(new HttpWebConnection(client) {
    @Override
    protected WebResponse newWebResponseInstance(
        final WebResponseData responseData, final long loadTime, final WebRequest request) {
      return new WebResponseProxy(super.newWebResponseInstance(responseData, loadTime, request));
    }
  });
  return client;
}

相关文章