jevy
jevy

Reputation: 197

Capybara's Selenium driver won't click Jquery Mobile buttons

Capybara's Selenium driver won't click on JQuery Mobile formatted buttons. It thinks the button is not visible.

Has anyone seen this issue and got around it?

I created a "greenfield" app demonstrating this issue here: https://github.com/jevy/JQuery_Mobile_Capybara

@javascript
Scenario: Clicking a button doesn't complain # features/click_jq_mobile_button.feature:7
  Given I am on the home page                # features/step_definitions/web_steps.rb:44
  Given I press "Some Button"                # features/step_definitions/web_steps.rb:52
    Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError)
    [remote server] resource://fxdriver/modules/atoms.js:9442:in `unknown'
    [remote server] file:///var/folders/fG/fGiEX6gLHQyvWGWb-5MpfU+++TI/-Tmp-/webdriver-profile20110525-21904-h3s00b/extensions/[email protected]/components/nsCommandProcessor.js:256:in `unknown'
    [remote server] file:///var/folders/fG/fGiEX6gLHQyvWGWb-5MpfU+++TI/-Tmp-/webdriver-profile20110525-21904-h3s00b/extensions/[email protected]/components/nsCommandProcessor.js:305:in `unknown'
    [remote server] file:///var/folders/fG/fGiEX6gLHQyvWGWb-5MpfU+++TI/-Tmp-/webdriver-profile20110525-21904-h3s00b/extensions/[email protected]/components/nsCommandProcessor.js:320:in `unknown'
    [remote server] file:///var/folders/fG/fGiEX6gLHQyvWGWb-5MpfU+++TI/-Tmp-/webdriver-profile20110525-21904-h3s00b/extensions/[email protected]/components/nsCommandProcessor.js:197:in `unknown'
    (eval):2:in `send'
    (eval):2:in `click_button'
    ./features/step_definitions/web_steps.rb:53:in `/^(?:|I )press "([^"]*)"$/'
    features/click_jq_mobile_button.feature:9:in `Given I press "Some Button"'

Failing Scenarios:
cucumber features/click_jq_mobile_button.feature:7 # Scenario: Clicking a button doesn't complain

Upvotes: 1

Views: 1232

Answers (3)

Chris Beck
Chris Beck

Reputation: 1929

Capybara's DOM polling might be finding your selector while the page is loaded and inactive (before the jQueryMobile page transition effect is complete). I solved this problem by scoping my selector as follows:

before do
  click_link "get_ajax_page"
  should have_selector(".ui-page-active #my_id")
  click_link "link_on_ajax_page"
end

The have_selector will block the script until the page is active.

Upvotes: 1

bmustata
bmustata

Reputation: 597

How about trying:

driver.ExecuteScript("$('#buttonName').click()");

this will work with Selenium 2 and jQuery mobile.

Upvotes: 1

Dan Croak
Dan Croak

Reputation: 1669

This sounds familiar but I think we may have solved it by moving off Selenium to capybara-webkit:

http://robots.thoughtbot.com/post/4583605733/capybara-webkit

Upvotes: 0

Related Questions