Capybara+Selenium 找不到 FB-Connect 链接/按钮

发布于 2024-09-26 23:45:23 字数 1196 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入画浅相思 2024-10-03 23:45:23

我不使用 Cucumber,但据我了解,当您在 Capybara 中查找元素时,它会检查“内容”和“名称”。当然,它明确表示它正在查找错误消息中的 ID,所以可能不会。我认为实际的问题是:

no link with

在您的错误消息中,因为这意味着它正在寻找链接,而您那里没有链接,所以您有一个 javascript 元素。

不过,如果您想检查“id”,我会尝试专门要求它查找参数 id=“mylogin”的元素,也许通过不同的方法,例如 xpath。

再说一次,我不知道黄瓜,但只要水豚我就会这样做:

page.first(:xpath, '//[@id="mylogin"]').click

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:

no link with

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:

page.first(:xpath, '//[@id="mylogin"]').click
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文