node.js - WebdriverJS/IO 和 PhantomJS - 具有属性选择器的点击处理程序不适用于 PhantomJS

标签 node.js selenium-webdriver phantomjs ghostdriver webdriver-io

我目前正在使用 WebdriverJS 和 PhantomJS 编写应用程序测试套件。 为了确保我的测试有效,我首先通过 Chrome 运行它们,它们都工作正常。然而,当我将 Chrome 换成 PhantomJS 时,测试失败了。

这个问题-WebDriver PhantomJS Unable to find element, but works fine with Firefox - 似乎概述了一个非常相似的问题,但所附的解决方案似乎没有帮助。

以下是适用于 Chrome 但不适用于 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' 
});

但是当我运行测试并将 logLevel 设置为“verbose”时,我收到如下错误消息:

[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+ 选择器(如“[data-id='1568911']”,甚至“#foo”)不能通过 WebdriverJS 在 PhantomJS 上工作?这是 PhantomJS 错误、WebdriverJS 错误还是我在实现中犯的错误?

最佳答案

So at least for the google page it should mean that WebdriverJS does something wrong with the userAgent string. But that doesn't mean that it is the same issue as for your original page.

类似的事情...

默认的 WebdriverJS 用户代理值很好。问题(至少对于我正在测试的页面)来自一段代码,大致如下:

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

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

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

呵呵。

也就是说,我不明白为什么有人想要在始终在线的产品中使用 navigator.onLine 值。只能在别人的代码中找到的经典之一......

令人痛苦的错误。

感谢您的帮助。

关于node.js - WebdriverJS/IO 和 PhantomJS - 具有属性选择器的点击处理程序不适用于 PhantomJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26844502/

相关文章:

java - 如何在@AfterMethod 中获取TestNG/Selenium 的测试结果状态?

java - Selenium 2 - 如何在隐式等待时检查元素是否不存在?

java - 无法在 Java 中使用 phantomJS 处理警报

css - Mediawiki Tweeki bootstrap 打印样式

node.js - 使用 AWS Lambda 查询数据库,并将结果推送到 Geckoboard

selenium-webdriver - 单击坐标而不识别元素

javascript - 使用 Javascript 访问 JSON 解析 SOAP 信封

angular - Phantomjs 在 Jenkins 上崩溃 : Auto configuration failed

node.js - 为什么使用不同文件的 Express 路由不起作用?

node.js - NodeJs 数组中的项变量仅采用 for 循环中的第一个值