本文整理了Java中com.gargoylesoftware.htmlunit.WebClient.isJavaScriptEnabled()
方法的一些代码示例,展示了WebClient.isJavaScriptEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.isJavaScriptEnabled()
方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebClient
类名称:WebClient
方法名:isJavaScriptEnabled
[英]Returns true if JavaScript is enabled and the script engine was loaded successfully.
[中]如果启用了JavaScript且脚本引擎已成功加载,则返回true。
代码示例来源:origin: org.openqa.selenium.webdriver/webdriver-htmlunit
public boolean isJavascriptEnabled() {
return webClient.isJavaScriptEnabled();
}
代码示例来源:origin: org.jenkins-ci/htmlunit
private HtmlElement getFirstChildElement(final DomNode parent) {
if (parent instanceof HtmlNoScript
&& getPage().getEnclosingWindow().getWebClient().isJavaScriptEnabled()) {
return null;
}
DomNode node = parent.getFirstChild();
while (node != null && node instanceof HtmlElement == false) {
node = node.getNextSibling();
}
return (HtmlElement) node;
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
private HtmlElement getFirstChildElement(final DomNode parent) {
if (parent instanceof HtmlNoScript
&& getPage().getEnclosingWindow().getWebClient().isJavaScriptEnabled()) {
return null;
}
DomNode node = parent.getFirstChild();
while (node != null && node instanceof HtmlElement == false) {
node = node.getNextSibling();
}
return (HtmlElement) node;
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
private HtmlElement getFirstChildElement(final DomNode parent) {
if (parent instanceof HtmlNoScript
&& getPage().getEnclosingWindow().getWebClient().isJavaScriptEnabled()) {
return null;
}
DomNode node = parent.getFirstChild();
while (node != null && node instanceof HtmlElement == false) {
node = node.getNextSibling();
}
return (HtmlElement) node;
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* Fires the event on the element. Nothing is done if JavaScript is disabled.
* @param event the event to fire
* @return the execution result, or <tt>null</tt> if nothing is executed
*/
public ScriptResult fireEvent(final Event event) {
final WebClient client = getPage().getWebClient();
if (!client.isJavaScriptEnabled()) {
return null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Firing " + event);
}
final HTMLElement jsElt = (HTMLElement) getScriptObject();
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
return jsElt.fireEvent(event);
}
};
final ContextFactory cf = client.getJavaScriptEngine().getContextFactory();
final ScriptResult result = (ScriptResult) cf.call(action);
if (event.isAborted(result)) {
preventDefault();
}
return result;
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* Fires the event on the element. Nothing is done if JavaScript is disabled.
* @param event the event to fire
* @return the execution result, or <tt>null</tt> if nothing is executed
*/
public ScriptResult fireEvent(final Event event) {
final WebClient client = getPage().getWebClient();
if (!client.isJavaScriptEnabled()) {
return null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Firing " + event);
}
final HTMLElement jsElt = (HTMLElement) getScriptObject();
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
return jsElt.fireEvent(event);
}
};
final ContextFactory cf = client.getJavaScriptEngine().getContextFactory();
final ScriptResult result = (ScriptResult) cf.call(action);
if (event.isAborted(result)) {
preventDefault();
}
return result;
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* Returns an auto-refresh string if specified. This will look in both the meta
* tags (taking care of <noscript> if any) and inside the HTTP response headers.
* @return the auto-refresh string
*/
private String getRefreshStringOrNull() {
final boolean javaScriptEnabled = getWebClient().isJavaScriptEnabled();
for (final HtmlMeta meta : getMetaTags("refresh")) {
if ((!javaScriptEnabled || getFirstParent(meta, HtmlNoScript.TAG_NAME) == null)) {
return meta.getContentAttribute();
}
}
return getWebResponse().getResponseHeaderValue("Refresh");
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* Returns an auto-refresh string if specified. This will look in both the meta
* tags (taking care of <noscript> if any) and inside the HTTP response headers.
* @return the auto-refresh string
*/
private String getRefreshStringOrNull() {
final boolean javaScriptEnabled = getWebClient().isJavaScriptEnabled();
for (final HtmlMeta meta : getMetaTags("refresh")) {
if ((!javaScriptEnabled || getFirstParent(meta, HtmlNoScript.TAG_NAME) == null)) {
return meta.getContentAttribute();
}
}
return getWebResponse().getResponseHeaderValue("Refresh");
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* Returns an auto-refresh string if specified. This will look in both the meta
* tags (taking care of <noscript> if any) and inside the HTTP response headers.
* @return the auto-refresh string
*/
private String getRefreshStringOrNull() {
final boolean javaScriptEnabled = getWebClient().isJavaScriptEnabled();
for (final HtmlMeta meta : getMetaTags("refresh")) {
if ((!javaScriptEnabled || getFirstParent(meta, HtmlNoScript.TAG_NAME) == null)) {
return meta.getContentAttribute();
}
}
return getWebResponse().getResponseHeaderValue("Refresh");
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* Fires the event on the element. Nothing is done if JavaScript is disabled.
* @param event the event to fire
* @return the execution result, or <tt>null</tt> if nothing is executed
*/
public ScriptResult fireEvent(final Event event) {
final WebClient client = getPage().getWebClient();
if (!client.isJavaScriptEnabled()) {
return null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Firing " + event);
}
final HTMLElement jsElt = (HTMLElement) getScriptObject();
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
return jsElt.fireEvent(event);
}
};
final ContextFactory cf = client.getJavaScriptEngine().getContextFactory();
final ScriptResult result = (ScriptResult) cf.call(action);
if (event.isAborted(result)) {
preventDefault();
}
return result;
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/>
*
* @param node the node that has just been added to the document
*/
void notifyNodeAdded(final DomNode node) {
if (node instanceof HtmlElement) {
boolean insideNoScript = false;
if (getWebClient().isJavaScriptEnabled()) {
for (DomNode parent = node.getParentNode(); parent != null; parent = parent.getParentNode()) {
if (parent instanceof HtmlNoScript) {
insideNoScript = true;
break;
}
}
}
if (!insideNoScript) {
addMappedElement((HtmlElement) node, true);
}
if (node.getNodeName().equals("base")) {
calculateBase();
}
}
node.onAddedToPage();
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* Sets the ready state on any deferred scripts, if necessary.
*/
private void setReadyStateOnDeferredScriptsIfNeeded() {
if (getWebClient().isJavaScriptEnabled() && getWebClient().getBrowserVersion().isIE()) {
final List<HtmlElement> elements = getDocumentElement().getHtmlElementsByTagName("script");
for (final HtmlElement e : elements) {
if (e instanceof HtmlScript) {
final HtmlScript script = (HtmlScript) e;
if (script.isDeferred()) {
script.setAndExecuteReadyState(READY_STATE_COMPLETE);
}
}
}
}
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* Sets the ready state on any deferred scripts, if necessary.
*/
private void setReadyStateOnDeferredScriptsIfNeeded() {
if (getWebClient().isJavaScriptEnabled() && getWebClient().getBrowserVersion().isIE()) {
final List<HtmlElement> elements = getDocumentElement().getHtmlElementsByTagName("script");
for (final HtmlElement e : elements) {
if (e instanceof HtmlScript) {
final HtmlScript script = (HtmlScript) e;
if (script.isDeferred()) {
script.setAndExecuteReadyState(READY_STATE_COMPLETE);
}
}
}
}
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* Sets the ready state on any deferred scripts, if necessary.
*/
private void setReadyStateOnDeferredScriptsIfNeeded() {
if (getWebClient().isJavaScriptEnabled() && getWebClient().getBrowserVersion().isIE()) {
final List<HtmlElement> elements = getDocumentElement().getHtmlElementsByTagName("script");
for (final HtmlElement e : elements) {
if (e instanceof HtmlScript) {
final HtmlScript script = (HtmlScript) e;
if (script.isDeferred()) {
script.setAndExecuteReadyState(READY_STATE_COMPLETE);
}
}
}
}
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* Executes any deferred scripts, if necessary.
*/
private void executeDeferredScriptsIfNeeded() {
if (!getWebClient().isJavaScriptEnabled()) {
return;
}
if (!getWebClient().getBrowserVersion().isIE()) {
return;
}
final HtmlElement doc = getDocumentElement();
final List<HtmlElement> elements = doc.getHtmlElementsByTagName("script");
for (final HtmlElement e : elements) {
if (e instanceof HtmlScript) {
final HtmlScript script = (HtmlScript) e;
if (script.isDeferred()) {
script.executeScriptIfNeeded(true);
}
}
}
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* Executes any deferred scripts, if necessary.
*/
private void executeDeferredScriptsIfNeeded() {
if (!getWebClient().isJavaScriptEnabled()) {
return;
}
if (!getWebClient().getBrowserVersion().isIE()) {
return;
}
final HtmlElement doc = getDocumentElement();
final List<HtmlElement> elements = doc.getHtmlElementsByTagName("script");
for (final HtmlElement e : elements) {
if (e instanceof HtmlScript) {
final HtmlScript script = (HtmlScript) e;
if (script.isDeferred()) {
script.executeScriptIfNeeded(true);
}
}
}
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* Executes any deferred scripts, if necessary.
*/
private void executeDeferredScriptsIfNeeded() {
if (!getWebClient().isJavaScriptEnabled()) {
return;
}
if (!getWebClient().getBrowserVersion().isIE()) {
return;
}
final HtmlElement doc = getDocumentElement();
final List<HtmlElement> elements = doc.getHtmlElementsByTagName("script");
for (final HtmlElement e : elements) {
if (e instanceof HtmlScript) {
final HtmlScript script = (HtmlScript) e;
if (script.isDeferred()) {
script.executeScriptIfNeeded(true);
}
}
}
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/>
*
* Execute a Function in the given context.
*
* @param function the JavaScript Function to call
* @param thisObject the "this" object to be used during invocation
* @param args the arguments to pass into the call
* @param htmlElementScope the HTML element for which this script is being executed
* This element will be the context during the JavaScript execution. If null,
* the context will default to the page.
* @return a ScriptResult which will contain both the current page (which may be different than
* the previous page and a JavaScript result object.
*/
public ScriptResult executeJavaScriptFunctionIfPossible(final Function function, final Scriptable thisObject,
final Object[] args, final DomNode htmlElementScope) {
if (!getWebClient().isJavaScriptEnabled()) {
return new ScriptResult(null, this);
}
final JavaScriptEngine engine = getWebClient().getJavaScriptEngine();
final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope);
return new ScriptResult(result, getWebClient().getCurrentWindow().getEnclosedPage());
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/>
*
* Execute a Function in the given context.
*
* @param function the JavaScript Function to call
* @param thisObject the "this" object to be used during invocation
* @param args the arguments to pass into the call
* @param htmlElementScope the HTML element for which this script is being executed
* This element will be the context during the JavaScript execution. If null,
* the context will default to the page.
* @return a ScriptResult which will contain both the current page (which may be different than
* the previous page and a JavaScript result object.
*/
public ScriptResult executeJavaScriptFunctionIfPossible(final Function function, final Scriptable thisObject,
final Object[] args, final DomNode htmlElementScope) {
if (!getWebClient().isJavaScriptEnabled()) {
return new ScriptResult(null, this);
}
final JavaScriptEngine engine = getWebClient().getJavaScriptEngine();
final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope);
return new ScriptResult(result, getWebClient().getCurrentWindow().getEnclosedPage());
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/>
*
* Execute a Function in the given context.
*
* @param function the JavaScript Function to call
* @param thisObject the "this" object to be used during invocation
* @param args the arguments to pass into the call
* @param htmlElementScope the HTML element for which this script is being executed
* This element will be the context during the JavaScript execution. If null,
* the context will default to the page.
* @return a ScriptResult which will contain both the current page (which may be different than
* the previous page and a JavaScript result object.
*/
public ScriptResult executeJavaScriptFunctionIfPossible(final Function function, final Scriptable thisObject,
final Object[] args, final DomNode htmlElementScope) {
if (!getWebClient().isJavaScriptEnabled()) {
return new ScriptResult(null, this);
}
final JavaScriptEngine engine = getWebClient().getJavaScriptEngine();
final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope);
return new ScriptResult(result, getWebClient().getCurrentWindow().getEnclosedPage());
}
内容来源于网络,如有侵权,请联系作者删除!