chromedriver可以使用,但"phantomjs无法使用css选择器找到项目" [英] chromedriver works but "phantomjs unable to locate item using css selector"

查看:234
本文介绍了chromedriver可以使用,但"phantomjs无法使用css选择器找到项目"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的工作设计一些端到端测试,并且已经通过chromedriver使用nightwatch.js启动并运行了它.但是,我们希望在服务器上运行它,因此我希望能够使用phantomjs运行它.尽管使用chromedriver进行测试时不会出现意外,但Phantomjs会产生以下错误"phantomjs无法使用css选择器定位项目"

I'm designing some end to end testing for my job, and I've got it up and running using nightwatch.js through chromedriver. However, we're looking to have this run on our servers, and so I wanted to be able to run it using phantomjs. Although the test performs without incident using chromedriver, Phantomjs yields the following error "phantomjs unable to locate item using css selector"

有什么想法吗?我一直在互联网上搜寻解决方案,但无济于事.

Any ideas? I've scoured the internet for a solution, to no avail.

推荐答案

首先,在此处检查决定'评论:

First, check decates' comment here: https://github.com/nightwatchjs/nightwatch/issues/243#issuecomment-94287511

看看如何根据从浏览器传递到站点的用户代理信息,站点返回不同的XHTML数据?因此,如果您想使用phantomjs,但可以通过用户代理将其欺骗为其他浏览器,则可以配置phantomjs的用户代理功能,如下所示(欺骗Mac Chrome):

See how depending on the user-agent info passed from your browser to the site, the site returns different XHTML data? So if you want to use phantomjs, but are okay with it spoofing as a different browser via the user agent, you can configure phantomjs' user-agent capabilities, like this (spoofing Mac Chrome):

"desiredCapabilities": {
  "browserName": "phantomjs",
  "phantomjs.cli.args" : ["--ignore-ssl-errors=true"],
  "phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"
}

然后,您的测试应与其他浏览器相同.使用您喜欢的任何浏览器,您都可以检查它在此处发送的用户代理字符串: http://www.httpuseragent.org /.这是其他一些示例:

Then your tests should act the same as your other browser. Using any browser you like, you can check the user-agent string that it sends here: http://www.httpuseragent.org/. Here are some other examples:

// Mac Chrome 46
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"

// Windows Chrome 46
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"

// Mac Firefox 42.0
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:42.0) Gecko/20100101 Firefox/42.0"

// Windows Firefox 42.0
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Windows NT 6.3; rv:42.0) Gecko/20100101 Firefox/42.0"

// PhantomJS 2.0
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1"

这篇关于chromedriver可以使用,但"phantomjs无法使用css选择器找到项目"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆