【发布时间】:2015-09-07 19:02:10
【问题描述】:
我遇到了一个点击事件没有触发的问题(有时会,有时不会),这总是在以无头状态运行浏览器时发生。
我会像这样使用.click 方法
find("#peoplePreview > tbody > tr:first-of-type > td > a").click
在调试模式下运行 phantomjs 时,我得到了
"name":"find","args":["css","#peoplePreview > tbody > tr:first-of-type > td > a"]}
{"response":{"page_id":18,"ids":[10]}}
{"name":"click","args":[18,10]}
{"response":{"position":{"x":114,"y":523.5}}}
据我所知,该元素已被找到,并且该元素在正确的坐标处单击,但未触发该事件
有人遇到过这种情况或有其他方法可以触发此事件吗?
这就是我设置 poltergeist 的方式
Capybara.register_driver :headless do |app|
options = {
:js_errors => false,
:inspector => true,
:debug => true,
:path => '/usr/bin/',
:phantomjs_options => ['--ignore-ssl-errors=yes', '--ssl-protocol=any']
}
Capybara::Poltergeist::Driver.new(app, options)
end
谢谢
【问题讨论】:
-
请发布完整的代码,(通常你应该像这样调用点击方法
...td > a").click();) -
可能是 PhantomJS 中带有
:first-of-type选择器的错误。尝试使用 XPath 而不是 CSS 选择器,并尽量不要专门为“tbody”编写。
标签: javascript phantomjs capybara