WebdriverJS / IO&PhantomJS – 使用属性select器的Click处理程序不能与PhantomJS一起使用

我目前正在用WebdriverJS和PhantomJS编写一个应用程序testing套件。 为了确保我的testing工作,我首先通过Chrome运行它们,并且它们都正常工作。 当我换出PhantomJS的Chrome时,testing会中断。

这个问题 – WebDriver PhantomJS无法find元素,但与Firefox工作正常似乎概述了一个非常类似的问题,但附带的解决scheme似乎没有帮助。

下面是一个在Chrome上可以使用的types的简单例子,但不是PhantomJS上的例子:

var client = webdriverjs.remote({ desiredCapabilities: { browserName: 'chrome' }, logLevel: 'silent' }); client.waitForExist("[data-id='1568911']", function(e){ client.click("[data-id='1568911']", function(e){ assert(!e, "Should click on a specific element:" + element); }); }); 

在PhantomJS上运行时,我显然首先更改WebdriverJS选项:

 var client = webdriverjs.remote({ desiredCapabilities: { browserName: 'phantomjs', 'phantomjs.binary.path': "path/to/phantomjs" }, logLevel: 'silent' }); 

但是当我运行testing并将logLevel设置为“详细”时,我收到如下所示的错误消息:

 [12:43:34]: COMMAND POST "/wd/hub/session/eb2b0a4b-e659-4607-bec0-82209bd6539a/element" [12:43:34]: DATA {"using":"css selector","value":"[data-id='1568911']"} [12:43:35]: ERROR UnknownError An unknown server-side error occurred while processing the command. {"errorMessage":"Unable to find element with css selector '[data-id='1568911']'","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"54","Content-Type":"application/json; charset=utf-8","Host":"localhost:12784","User-Agent":"Apache-HttpClient/4.3.2 (java 1.5)"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"css selector\",\"value\":\"[data-id='1568911']\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/2e1ff0a0-68d7-11e4-ad4c-3105ad572a89/element"}} 

为什么常见的CSS2 +select器像“[data-id ='1568911']”,甚至“#foo”,都不能通过WebdriverJS在PhantomJS上运行? 是PhantomJS错误,WebdriverJS错误还是我在实现中犯的错误?

所以至less对于谷歌页面来说,它应该意味着WebdriverJS在userAgentstring中做了一些错误。 但这并不意味着它与原始页面是同一个问题。

像那样的…

默认的WebdriverJS用户代理值是好的。 问题(至less在我testing的页面上)来自一段代码,看起来大致如下:

 if(navigator.onLine){ renderPage() } else doSomethingElse(); 

看来,PhantomJS总是将navigator.onLine设置为false …

https://github.com/ariya/phantomjs/issues/10647

卫生署。

这就是说,我不明白为什么有人会想要在一个永远在线的产品中使用navigator.onLine值。 那些只能在别人的代码中find的经典之一…

痛苦的错误。

谢谢您的帮助。