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

x33g5p2x  于2022-02-02 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(231)

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

WebClient.getOptions介绍

[英]Returns the options object of this WebClient.
[中]返回此WebClient的选项对象。

代码示例

代码示例来源:origin: apache/shiro

@Before
public void beforeTest() {
  webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
}

代码示例来源:origin: javaee-samples/javaee7-samples

@Before
public void setUp() {
  webClient = new WebClient();
  webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
}

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

public class MyHtmlUnitDriver extends HtmlUnitDriver {

...

 @Override
  protected WebClient modifyWebClient(WebClient client) {
    //currently does nothing, but may be changed in future versions
    WebClient modifiedClient = super.modifyWebClient(client);

    modifiedClient.getOptions().setThrowExceptionOnScriptError(false);
    return modifiedClient;
  }
}

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

final WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setCssEnabled(false);//if you don't need css
webClient.getOptions().setJavaScriptEnabled(false);//if you don't need js
HtmlPage page = webClient.getPage("http://XXX.xxx.xx");
...

代码示例来源: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

LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);

WebClient client = new WebClient(BrowserVersion.CHROME);
client.getOptions().setJavaScriptEnabled(true);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);

String url = "https://accounts.google.com/login";
final HtmlPage page = client.getPage(url);

System.out.println(page.asText());

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

/**
 * Returns the timeout to use for socket and connection timeouts for HttpConnectionManager.
 * Is overridden to 0 by StreamingWebConnection which keeps reading after a timeout and
 * must have long running connections explicitly terminated.
 * @return the WebClient's timeout
 */
protected int getTimeout() {
  return webClient_.getOptions().getTimeout();
}

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

HtmlUnitDriver driver = new HtmlUnitDriver(){
   @Override
   protected WebClient newWebClient(BrowserVersion version) {
     WebClient webClient = super.newWebClient(version);
     webClient.getOptions().setThrowExceptionOnScriptError(false);
     return webClient;
   }
 };

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

WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_9);
   webClient.getOptions().setJavaScriptEnabled(true);
   webClient.getOptions().setRedirectEnabled(true);
   webClient.getOptions().setThrowExceptionOnScriptError(false);
   webClient.getOptions().setCssEnabled(true);     
   HtmlPage page = (HtmlPage) webClient.getPage("http://www.sears.com/search=little tikes&Little Tikes?filter=Brand&keywordSearch=false&vName=Toys+%26+Games&catalogId=12605&catPrediction=false&previousSort=ORIGINAL_SORT_ORDER&viewItems=50&storeId=10153&adCell=W3");
   WebResponse response = page.getWebResponse();
   String content = response.getContentAsString();
   System.out.println(page.getUrl());

代码示例来源:origin: com.atlassian.selenium/atlassian-webdriver-core

@Override
  protected WebClient modifyWebClient(final WebClient client)
  {
    // "real" browsers don't throw script errors back to webdriver, so stop htmlunit from doing it too
    client.getOptions().setThrowExceptionOnScriptError(false);
    return client;
  }
};

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

private void configureTimeout(final HttpClientBuilder builder, final int timeout) {
  final InetAddress localAddress = webClient_.getOptions().getLocalAddress();
  final RequestConfig.Builder requestBuilder = createRequestConfigBuilder(timeout, localAddress);
  builder.setDefaultRequestConfig(requestBuilder.build());
  builder.setDefaultSocketConfig(createSocketConfigBuilder(timeout).build());
  getHttpContext().removeAttribute(HttpClientContext.REQUEST_CONFIG);
  usedOptions_.setTimeout(timeout);
}

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

/**
 * Returns the {@code width} property.
 * @return the {@code width} property
 */
@JsxGetter
public int getWidth() {
  return ((Window) getParentScope()).getWebWindow().getWebClient().getOptions().getScreenWidth();
}

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

/**
 * Sets the web client's current homepage. Part of the <tt>#default#homePage</tt>
 * default IE behavior implementation.
 * @param url the new homepage URL
 */
public void setHomePage(final String url) {
  getDomNodeOrDie().getPage().getEnclosingWindow().getWebClient().getOptions().setHomePage(url);
}

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

/**
 * Indicates if Java is enabled.
 * @return true/false (see {@link com.gargoylesoftware.htmlunit.WebClientOptions#isAppletEnabled()}
 */
@JsxFunction
public boolean javaEnabled() {
  return getWindow().getWebWindow().getWebClient().getOptions().isAppletEnabled();
}

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

/**
 * Returns the {@code height} property.
 * @return the {@code height} property
 */
@JsxGetter
public int getHeight() {
  return ((Window) getParentScope()).getWebWindow().getWebClient().getOptions().getScreenHeight();
}

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

/**
   * Returns the {@code doNotTrack} property.
   * @return the {@code doNotTrack} property
   */
  @JsxGetter(IE)
  public Object getDoNotTrack() {
    final WebClient client = getWindow().getWebWindow().getWebClient();
    if (client.getOptions().isDoNotTrackEnabled()) {
      return 1;
    }
    return null;
  }
}

代码示例来源:origin: HtmlUnit/htmlunit

/**
 * Returns the {@code width} property.
 * @return the {@code width} property
 */
@JsxGetter
public int getWidth() {
  return ((Window) getParentScope()).getWebWindow().getWebClient().getOptions().getScreenWidth();
}

代码示例来源:origin: HtmlUnit/htmlunit

/**
 * Sets the web client's current homepage. Part of the <tt>#default#homePage</tt>
 * default IE behavior implementation.
 * @param url the new homepage URL
 */
public void setHomePage(final String url) {
  getDomNodeOrDie().getPage().getEnclosingWindow().getWebClient().getOptions().setHomePage(url);
}

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

/**
 * Causes the web client to navigate to the current home page. Part of the
 * <tt>#default#homePage</tt> default IE behavior implementation.
 * @throws IOException if loading home page fails
 */
public void navigateHomePage() throws IOException {
  final WebClient webClient = getDomNodeOrDie().getPage().getEnclosingWindow().getWebClient();
  webClient.getPage(webClient.getOptions().getHomePage());
}

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

private void configureHttpsScheme(final HttpClientBuilder builder) {
  final WebClientOptions options = webClient_.getOptions();
  final SSLConnectionSocketFactory socketFactory =
      HtmlUnitSSLConnectionSocketFactory.buildSSLSocketFactory(options);
  builder.setSSLSocketFactory(socketFactory);
  usedOptions_.setUseInsecureSSL(options.isUseInsecureSSL());
  usedOptions_.setSSLClientCertificateStore(options.getSSLClientCertificateStore());
  usedOptions_.setSSLTrustStore(options.getSSLTrustStore());
  usedOptions_.setSSLClientCipherSuites(options.getSSLClientCipherSuites());
  usedOptions_.setSSLClientProtocols(options.getSSLClientProtocols());
  usedOptions_.setProxyConfig(options.getProxyConfig());
}

相关文章

WebClient类方法