我正在尝试在C#中使用Selenium RemoteWebDriver,基本上我要做的就是在javascript完成对DOM的操作 后
以编程方式抓取网页的html (不弹出浏览器窗口。)
首先,我像这样启动selenium-server.jar:
C:\ Program Files \ selenium-server > java -jar“ C:\ Program Files \
selenium-server \ selenium-server.jar”
13:34:46.163 INFO - Java: Sun Microsystems Inc. 19.1-b02
13:34:46.166 INFO - OS: Windows 7 6.1 amd64
13:34:46.174 INFO - v2.0 [a2], with Core v2.0 [a2]
13:34:46.277 INFO - RemoteWebDriver instances should connect to: **http://127.0.0.1:4444/wd/hub**
13:34:46.278 INFO - Version Jetty/5.1.x
13:34:46.279 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
13:34:46.280 INFO - Started HttpContext[/selenium-server,/selenium-server]
13:34:46.280 INFO - Started HttpContext[/,/]
13:34:46.311 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@6019d0
a1
13:34:46.312 INFO - Started HttpContext[/wd,/wd]
13:34:46.316 INFO - Started SocketListener on 0.0.0.0:4444
13:34:46.316 INFO - Started org.openqa.jetty.jetty.Server@199a0c7c
接下来,我尝试从一个测试用例运行此行:
var driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"), DesiredCapabilities.Chrome());
这行错误:
Test 'Housters.Test.ScrapeTest.TestSelenium' failed: OpenQA.Selenium.WebDriverException : Unexpected error. {"message":"java.lang.NullPointerException","localizedMessage":"java.lang.NullPointerException","cause":{"class":"java.lang.NullPointerException","stackTrace":[{"fileName":"DriverFactory.java","class":"java.lang.StackTraceElement","lineNumber":43,"className":"org.openqa.selenium.remote.server.DriverFactory","methodName":"getBestMatchFor","nativeMethod":false},{"fileName":"DriverFactory.java","class":"java.lang.StackTraceElement","lineNumber":76,"className":"org.openqa.selenium.remote.server.DriverFactory","methodName":"newInstance","nativeMethod":false},{"fileName":"Session.java","class":"java.lang.StackTraceElement","lineNumber":48,"className":"org.openqa.selenium.remote.server.Session$1","methodName":"call","nativeMethod":false},{"fileName":"Session.java","class":"java.lang.StackTraceElement","lineNumber":46,"className":"org.openqa.selenium.remote.server.Session$1","methodName":"call","nativeMethod":false},{"class":"java.lang.StackTraceElement","lineNumber":-1,"className":"java.util.concurrent.FutureTask$Sync","methodName":"innerRun","nativeMethod":false},{"class":"java.lang.StackTraceElement","lineNumber":-1,"className":"java.util.concurrent.FutureTask","methodName":"run","nativeMethod":false},{"class":"java.lang.StackTraceElement","lineNumber":-1,"className":"java.util.concurrent.ThreadPoolExecutor$Worker","methodName":"runTask","nativeMethod":false},{"class":"java.lang.StackTraceElement","lineNumber":-1,"className":"java.util.concurrent.ThreadPoolExecutor$Worker","methodName":"run","nativeMethod":false},{"class":"java.lang.StackTraceElement","lineNumber":-1,"className":"java.lang.Thread","methodName":"run","nativeMethod":false}]},"class":"java.util.concurrent.ExecutionException","stackTrace":[{"class":"java.lang.StackTraceElement","lineNumber":-1,"className":"java.util.concurrent.FutureTask$Sync","methodName":"innerGet","nativeMethod":false},{"class":"java.lang.StackTraceElement","lineNumber":-1,"className":"java.util.concurrent.FutureTask","methodName":"get","nativeMethod":false},{"fileName":"Session.java","class":"java.lang.StackTraceElement","lineNumber":68,"className":"org.openqa.selenium.remote.server.Session","methodName":"execute","nativeMethod":false},{"fileName":"Session.java","class":"java.lang.StackTraceElement","lineNumber":54,"className":"org.openqa.selenium.remote.server.Session","methodName":"<init>","nativeMethod":false},{"fileName":"DriverSessions.java","class":"java.lang.StackTraceElement","lineNumber":76,"className":"org.openqa.selenium.remote.server.DriverSessions","methodName":"newSession","nativeMethod":false},{"fileName":"NewSession.java","class":"java.lang.StackTraceElement","lineNumber":46,"className":"org.openqa.selenium.remote.server.handler.NewSession","methodName":"handle","nativeMethod":false},{"fileName":"ResultConfig.java","class":"java.lang.StackTraceElement","lineNumber":144,"className":"org.openqa.selenium.remote.server.rest.ResultConfig","methodName":"handle","nativeMethod":false},{"fileName":"DriverServlet.java","class":"java.lang.StackTraceElement","lineNumber":271,"className":"org.openqa.selenium.remote.server.DriverServlet","methodName":"handleRequest","nativeMethod":false},{"fileName":"DriverServlet.java","class":"java.lang.StackTraceElement","lineNumber":256,"className":"org.openqa.selenium.remote.server.DriverServlet","methodName":"doPost","nativeMethod":false},{"fileName":"HttpServlet.java","class":"java.lang.StackTraceElement","lineNumber":727,"className":"javax.servlet.http.HttpServlet","methodName":"service","nativeMethod":false},{"fileName":"HttpServlet.java","class":"java.lang.StackTraceElement","lineNumber":820,"className":"javax.servlet.http.HttpServlet","methodName":"service","nativeMethod":false},{"fileName":"ServletHolder.java","class":"java.lang.StackTraceElement","lineNumber":428,"className":"org.openqa.jetty.jetty.servlet.ServletHolder","methodName":"handle","nativeMethod":false},{"fileName":"ServletHandler.java","class":"java.lang.StackTraceElement","lineNumber":677,"className":"org.openqa.jetty.jetty.servlet.ServletHandler","methodName":"dispatch","nativeMethod":false},{"fileName":"ServletHandler.java","class":"java.lang.StackTraceElement","lineNumber":568,"className":"org.openqa.jetty.jetty.servlet.ServletHandler","methodName":"handle","nativeMethod":false},{"fileName":"HttpContext.java","class":"java.lang.StackTraceElement","lineNumber":1530,"className":"org.openqa.jetty.http.HttpContext","methodName":"handle","nativeMethod":false},{"fileName":"HttpContext.java","class":"java.lang.StackTraceElement","lineNumber":1482,"className":"org.openqa.jetty.http.HttpContext","methodName":"handle","nativeMethod":false},{"fileName":"HttpServer.java","class":"java.lang.StackTraceElement","lineNumber":909,"className":"org.openqa.jetty.http.HttpServer","methodName":"service","nativeMethod":false},{"fileName":"HttpConnection.java","class":"java.lang.StackTraceElement","lineNumber":820,"className":"org.openqa.jetty.http.HttpConnection","methodName":"service","nativeMethod":false},{"fileName":"HttpConnection.java","class":"java.lang.StackTraceElement","lineNumber":986,"className":"org.openqa.jetty.http.HttpConnection","methodName":"handleNext","nativeMethod":false},{"fileName":"HttpConnection.java","class":"java.lang.StackTraceElement","lineNumber":837,"className":"org.openqa.jetty.http.HttpConnection","methodName":"handle","nativeMethod":false},{"fileName":"SocketListener.java","class":"java.lang.StackTraceElement","lineNumber":245,"className":"org.openqa.jetty.http.SocketListener","methodName":"handleConnection","nativeMethod":false},{"fileName":"ThreadedServer.java","class":"java.lang.StackTraceElement","lineNumber":357,"className":"org.openqa.jetty.util.ThreadedServer","methodName":"handle","nativeMethod":false},{"fileName":"ThreadPool.java","class":"java.lang.StackTraceElement","lineNumber":534,"className":"org.openqa.jetty.util.ThreadPool$PoolThread","methodName":"run","nativeMethod":false}]}
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(DriverCommand driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
ScrapeTest.cs(36,0): at Housters.Test.ScrapeTest.TestSelenium()
在服务控制台窗口中,它显示此错误:
13:44:55.558 INFO - WebDriver remote server: Executing: [new session: null] at URL: /session)
13:44:55.560 INFO - WebDriver remote server: Exception: java.lang.NullPointerException
我正在尝试从Windows 7 x64执行此操作。我究竟做错了什么?这似乎是我想做的很多工作…
如果尝试在本地主机上运行Selenium2,则不需要使用RemoveWebDriver()和Selenium Server-您可以使用以下命令:
WebDriver driver = new ChromeDriver();
与使用RemoveWebDriver相比,我发现以这种方式在本地运行的问题更少,如果出现问题,您应该会找到更多可用的信息。
或者,您可以按照http://blog.stevensanderson.com/2010/03/30/using-htmlunit-on-net-for-
headless-browser-
automation/中的说明
直接使用HtmlUnit
问题内容: 我想使用系统蜂鸣器(并且只有在没有蜂鸣器/无法访问蜂鸣器时才使用扬声器)生成具有特定频率和长度(针对不同的声音信号)的蜂鸣声。我知道可以通过使用ioctl来做到这一点,但这需要root访问权限,而这是我所不希望的。 我知道我可以只使用“ beep”命令,但这将是一个依赖关系,如果可能的话,不应使用它(根本没有外部依赖关系,只有基本的linux库和C)。 我目前拥有的是以下代码(但这需要
当我运行命令< code>rake compile时,我很难弄清楚为什么我的rb_define_singleton和rb_define_method调用会中断。 首先,一个问题可能是我不确定最后一个整数参数实际上代表什么,以便决定使用什么值,我无法找到解释这一点的文档,但我觉得我只是猜测在那里,但问题似乎在第3个参数中,所以我担心的是 其次,我的构建失败,在调用时出现以下错误: 使编译../../
问题内容: 我有一个用Java(> 1.5)编写的项目。 是否可以用C#编写项目的一部分? 例如GUI和调用方法并实例化用Java编写的类? 如果是,怎么办? 问题答案: 有一种称为.NET的Java语言转换助手。您可以将Java类转换为c#并开始编码。 还有一个叫做JNBridge的东西(不是免费的)。
问题内容: 我正在尝试使用c创建tar文件。由于某种原因我无法使用 我的代码是: 运行此代码后,当我想解压时 我收到一个错误 我的C代码有什么问题? 问题答案: 我认为您需要在关闭tar文件之前调用tar_append_eof http://linux.die.net/man/3/tar_append_eof。 tar_append_eof()函数将EOF标记(两个全为零的块)写入与t关联的tar
本文向大家介绍Dapper.NET 在C#中使用Dapper,包括了Dapper.NET 在C#中使用Dapper的使用技巧和注意事项,需要的朋友参考一下 例 将连接包装在一个Using块中将关闭连接
问题内容: 在新的Go语言中,如何调用C 代码?换句话说,如何包装我的C 类并在Go中使用它们? 问题答案: 更新: 我已经成功地将一个小型测试C ++类与Go链接在一起 如果您使用C接口包装C ++代码,则应该可以使用cgo调用您的库(请参阅中的gmp示例)。 我不确定C ++中的类概念是否真的可以在Go中表达,因为它没有继承。 这是一个例子: 我有一个C ++类定义为: 我想在Go中使用。我将