Capybara+Selenium 找不到 FB-Connect 链接/按钮
我的 html 中有以下片段显示 FB-Connect 链接:
<fb:login-button id="mylogin" onlogin="try {
window.location.href = "http://localhost:3000/";
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('window.location.href = \"http://localhost:3000/\";'); throw e }"></fb:login-button>
手动单击它时效果很好。但是当在 Cucumber (@javascript 标签)中使用 Capybara+Selenium 时,他们似乎根本找不到要单击的元素。我尝试了几种组合来尝试匹配它,例如:
When I follow "mylogin" # or
When I press "mylogin"
我得到的答案如下:
no link with title, id or text 'mylogin' found (Capybara::ElementNotFound)
我还尝试匹配内部文本“登录”或“登录按钮”,但无济于事。尝试遵循 Cucumber 和 Capybara 的建议,单击非链接或按钮元素也有,但它不起作用。
我正在使用 Facebooker2 gem 生成链接:
#in my index.html.haml
= fb_connect_async_js
= fb_login_and_redirect('http://localhost:3000/', id: 'mylogin')
Gem versions:
capybara (0.3.9) #(actually pulling it from github directly)
xpath (~> 0.1.2)
selenium-webdriver (>= 0.0.27)
cucumber (0.9.2)
有任何提示吗?谢谢。
I have the following snippet in my html displaying a FB-Connect link:
<fb:login-button id="mylogin" onlogin="try {
window.location.href = "http://localhost:3000/";
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('window.location.href = \"http://localhost:3000/\";'); throw e }"></fb:login-button>
That works fine when manually clicking it. But when using Capybara+Selenium in Cucumber (@javascript tag), they don't seem to find the Element to click at all. I have tried several combinations trying to match it, like:
When I follow "mylogin" # or
When I press "mylogin"
And I get answers like:
no link with title, id or text 'mylogin' found (Capybara::ElementNotFound)
I also tried matching the inner text "Login" or "login-button", with no avail. Tried to follow the advice at Cucumber and Capybara, clicking a non-link or button element too, but it didn't work.
I'm using the Facebooker2 gem to generate the link:
#in my index.html.haml
= fb_connect_async_js
= fb_login_and_redirect('http://localhost:3000/', id: 'mylogin')
Gem versions:
capybara (0.3.9) #(actually pulling it from github directly)
xpath (~> 0.1.2)
selenium-webdriver (>= 0.0.27)
cucumber (0.9.2)
Any hint? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不使用 Cucumber,但据我了解,当您在 Capybara 中查找元素时,它会检查“内容”和“名称”。当然,它明确表示它正在查找错误消息中的 ID,所以可能不会。我认为实际的问题是:
在您的错误消息中,因为这意味着它正在寻找链接,而您那里没有链接,所以您有一个 javascript 元素。
不过,如果您想检查“id”,我会尝试专门要求它查找参数 id=“mylogin”的元素,也许通过不同的方法,例如 xpath。
再说一次,我不知道黄瓜,但只要水豚我就会这样做:
I don't use Cucumber, but from what I understand when you look for an element in Capybara, it checks for 'content' and 'name'. Of course, it's specifically saying that it's looking in the ID in your error message there, so maybe not. I think the actual problem is:
in your error message, since that means it is looking for a link, and you don't HAVE a link there, you have a javascript element.
Still, if you want to check on 'id', I'd try to specifically ask it to look for an element with the parameter id='mylogin', maybe through a different method, like xpath.
Again, I don't know about Cucumber, but just with Capybara I would do: