0

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.

Community
  • 1
  • 1
alp247
  • 208
  • 2
  • 7
  • I have also tried to increase wait time in several ways, like "sleep 10" and "Capybara.default_wait_time = 10". Didn't help. – alp247 Oct 12 '10 at 15:45

1 Answers1

0

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
GlyphGryph
  • 4,714
  • 4
  • 32
  • 43