我们正在选择我们的无头浏览器驱动程序解决方案,这将是Selenium WebDriver的一些实现.还有就是GhostDriver,利用的是PhantomJS在在一侧和后端HtmlUnitDriver其基于的HtmlUnit另一方.
PhantomJS使用Safari的渲染引擎WebKit来渲染页面,而HtmlUnitDriver使用其他浏览器没有使用的Rhino引擎(它只是"模拟"浏览器行为.最后一个事实被视为con,因为渲染行为可能与流行的浏览器.
我们认为,PhantomJS是一个更强大的候选人.但是,我们并不知道所有事情:)我们的决定是否还应考虑其他因素和权衡取舍?HtmlUnitDriver可以成为更好的解决方案的其他场景?
htmlunit phantomjs selenium-webdriver ghostdriver htmlunit-driver
我正在使用Selenium的WebDriver为我正在进行自我教育的ASP.NET MVC应用程序运行一些SpecFlow测试.
使用FirefoxDriver,ChromeDriver等所有需要很长时间来运行,它实际上是非常令人沮丧的使用(在我看来).
我读过一个HtmlUnitDriver据说比基于浏览器的驱动程序快得多的内容; 但我似乎无法在.NET客户端库中找到一个版本(只有Java).那里有.NET版本吗?
我正试图遍历一个网站,但在他们的一个页面上我收到此错误:
EcmaError: lineNumber=[671] column=[0] lineSource=[null] name=[TypeError] sourceName=[https://reservations.besodelsolresort.com/asp/CalendarPopup.js] message=[TypeError: Cannot read property "parentNode" from undefined (https://reservations.besodelsolresort.com/asp/CalendarPopup.js#671)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "parentNode" from undefined (https://reservations.besodelsolresort.com/asp/CalendarPopup.js#671)
Run Code Online (Sandbox Code Playgroud)
无论如何我可以忽略这个错误吗?如果日历加载正确,我并不特别在意.
我遇到了以下问题:我正在使用HtmlUnitDriver和Browserversion Firefox_3_6运行带有Selenium 2.9的JUnit testCase.JavaScript已启用.现在,当它应该调用并执行以下javaScript函数时,它什么都不做:
function openIdsDocument()
{
var windowBounds = getWindowBounds();
var XMLHTTP = getAjaxRequestObject("XYZ.do?availableWidth="+windowBounds.width+"&availableHeight="+windowBounds.height, "", true);
if (XMLHTTP != null)
{
XMLHTTP.onreadystatechange = function alertAJAXResponse()
{
if (XMLHTTP.readyState == 4)
{
window.location.href = getContextPath() + "ABC.do";
}
};
XMLHTTP.send("timestamp=" + <%=System.currentTimeMillis()%>);
}
getLoadingState();
}
Run Code Online (Sandbox Code Playgroud)
我想去ABC.do
如果我使用FirefoxDriver执行我的测试,它可以工作.
有没有办法让这个使用HtmlUnitDriver?如果我手动调用driver.get(" http://host/ABC.do "),我的测试工作,但这不是正确的方法.
我写了一个简单的网络刮刀来抓expedia.com.使用Java Selenium HtmlUnitDriver,如果我在本地运行它,我能够成功从网站上抓取数据.
然而,当我上到EC2服务器部署此,它总是返回我在哪里Expedia的检测它作为一个机器人的页面,因此,它会显示这个验证码,以证明人类正在访问它.
我认为它可能与ecpedia服务器的IP地址有关,这些服务器被expedia.com以某种方式列入黑名单?
我试过抓不同的网站,他们不关心/不做人体测试.
知道如何解决这个问题吗?
我尝试但仍被检测为机器人的东西:
更新:实际设置代理服务器给我一个不同的错误:
当前网址为https://www.expedia.com/things-to-do/search?location=Paris&pageNumber=1
htmlString:
<!--?xml version="1.0" encoding="ISO-8859-1"?-->
<html>
<head>
<title>
500 Internal Server Error
</title>
</head>
<body>
<h1> Internal Server Error </h1>
<p> The server encountered an internal error or misconfiguration and was unable to complete your request. </p>
<p> Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error. </p>
<p> More …Run Code Online (Sandbox Code Playgroud) selenium htmlunit web-scraping selenium-webdriver htmlunit-driver
我想在java中使用HTMLUnitDriver处理警报.我使用以下代码来使用firefox驱动程序处理警报,它工作正常.
Alert alert = driver.switchTo().alert();
alert.accept();
Run Code Online (Sandbox Code Playgroud)
但HTMLUnitDriver给出的错误就像
java.lang.UnsupportedOperationException: alert()
Run Code Online (Sandbox Code Playgroud)
如何处理警报箱?
我的Maven项目中有selenium-java 3.0.1.我已经读过这个版本没有与HTMLUnitDriver一起打包.所以,我在我的pom中分别包含了selenium-htmlunit-driver 2.52.0(最新版本).但是,当我这样做时,我在测试运行时遇到以下异常:
org.openqa.selenium.WebDriverException:java.lang.IllegalArgumentException:找不到声明的字段类org.apache.http.impl.client.HttpClientBuilder.sslcontext
根据这个链接,包括selenium-java和selenium-htmlunit-driver依赖应该就足够了.在某些情况下,可能还需要包含独立服务器,而我的项目则不然.无论如何我试过了,但这也没用.
selenium-htmlunit-driver 2.52.0在内部依赖于org.apache.httpcomponents 4.5.1.
selenium-java 2.47.0使用htmlunit-driver 2.47.0,它使用org.apache.httpcomponents 4.4.1.当我使用这些版本时,一切正常.
所以我的问题是,HTMLUnitDriver可以不与Selenium 3.0.x一起使用吗?或者我的理解在这里完全错了?
我正在尝试让HtmlUnitDriver在我的开发环境中工作.作为初学者,我尝试使用最新的selenium服务器jar实现以下页面中的示例:http: //code.google.com/p/selenium/wiki/GettingStarted
不幸的是,每当我尝试运行此程序时,我都会遇到以下异常:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element with name: q
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_16'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:853)
at org.openqa.selenium.By$ByName.findElement(By.java:292)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1404)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1094)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1401)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:419)
at Justin.Main.main(Main.java:30)
Run Code Online (Sandbox Code Playgroud)
我已经尝试修改我的代码以包含此处实现的修复:
我已经尝试driver.getCurrentUrl()在调用后获取页面的URL driver.get("http://www.google.com"),但返回的字符串是about:blank.
如果我使用FirefoxDriver运行它,这个例子中的类似代码肯定会有用,但是为了满足要求,我需要我的脚本用selenium运行无头(如果它是使用特定的BrowserVersion运行,只要它是无头的就可以了) .
任何帮助将不胜感激.
更新:
这是我正在尝试运行的代码.我只想看到我可以让HtmlUnitDriver使用像向Google输入搜索查询一样简单的工作.
package …Run Code Online (Sandbox Code Playgroud) 我有个问题。
是什么使得 FirefoxDriver 能够找到 WebElements 并在 java 代码中单击它们,但是当使用 HtmlUnitDriver 运行相同的代码时,却找不到相同的 WebElements。此外,当在 HtmlUnit 上运行相同的代码(应用 HtmlUnit 原理)时,找不到 WebElements,实际上代码返回 NullPointerException。有什么特别的原因吗?
我正在使用HtmlUnitDriver,这是我的代码.
HtmlUnitDriver driver = new HtmlUnitDriver(true);
driver.get("some url here");
Run Code Online (Sandbox Code Playgroud)
我得到以下例外:
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: SyntaxError: missing ; before statement (http://sales.liveperson.net/hcp/html/mTag.js?site=7824460#1(eval)#1)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:545)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:520)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:162)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:221)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:735)
at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:866)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:871)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1162)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:202)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:440)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:373)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:346)
... 8 more
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.
我正试图在eclipse中使用HTMLunitdriver.
我已经写了
WebDriver driver = new HtmlUnitDriver();
Run Code Online (Sandbox Code Playgroud)
所有jar文件都添加在buildpath中,但是我收到错误"HTMLunit驱动程序无法解析为类型".
任何人都可以提供任何指示吗?
主要区别在于,在GUI基和非GUI基(Headless)上执行。
我正在寻找所有无头浏览器之间的差异,但是很遗憾,我没有找到任何差异。我一个接一个地讲,这使我更加困惑。如果有人可以分享具有差异的简短信息,那就太好了,这很清楚。
selenium headless headless-browser selenium-webdriver htmlunit-driver
htmlunit-driver ×12
java ×8
selenium ×6
htmlunit ×5
javascript ×2
.net ×1
ajax ×1
ghostdriver ×1
headless ×1
maven ×1
phantomjs ×1
web-scraping ×1
webdriver ×1