phantomjs 中的 ghostdriver 似乎存在问题,当单击按钮后 HTTP 调用失败时,整个过程都会失败。
https://github.com/detro/ghostdriver/issues/202#issuecomment-19808784
该问题已在主分支中得到修复。说明了如何引用新文件而不是使用 phantomjs 中包含的 ghostdriver。
Java 在这里: https://github.com/detro/ghostdriver/issues/243
似乎有一个值
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY
但这在 C# 中不存在
所以都试过了
var opts = new PhantomJSOptions();
opts.AddAdditionalCapability("phantomjs.ghostdriver.path.property", "c:\\path\\src\\main.js");
但是不行,phantomjs 中的输出仍然显示旧版本
编辑1: 这与可以通过
设置的 phantomJS 路径不同 PhantomJSDriverService.CreateDefaultService("c:\path\to\phantomjs.exe")
我试图告诉 phantomjs 使用本地版本的 Ghostdriver,而不是 phantomjs iteself 中包含的 ghostdriver。
编辑2: 所以在这里挖掘 Java 代码文件 https://github.com/detro/ghostdriver/blob/master/binding/java/src/main/java/org/openqa/selenium/phantomjs/PhantomJSDriverService.java
我找到了设置Java静态字符串的代码
public static final String PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY = "phantomjs.ghostdriver.path";
这意味着我在上面设置错误,但在更正后仍然不起作用
var opts = new PhantomJSOptions();
opts.AddAdditionalCapability("phantomjs.ghostdriver.path", "c:\\path\\src\\main.js");
越来越暖和了......
最佳答案
你是对的,在当前发布的二进制版本的 .NET 绑定(bind)中没有办法做到这一点。然而,一个变化has just been made这将允许这样做。在 .NET 绑定(bind)中,代码如下所示:
var service = PhantomJSDriverService.CreateDefaultService(@"path\to\phantomjs.exe");
service.GhostDriverPath = @"path\to\ghostdriver\main.js";
var driver = new PhantomJSDriver(service);
通过PhantomJSDriverService
设置的内容和通过PhantomJSOptions
设置的内容之间的区别可以总结如下。如果该选项是要传递给 PhantomJS.exe 的命令行参数,则应通过服务进行设置;如果它是 GhostDriver 如何操作的选项,则应通过选项类进行设置。
关于c# - 设置 PhantomJSOptions.AddAdditionalCapability 以引用 ghostdriver 的本地副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17689934/