Capybara Selenium驱动程序不会单击Jquery Mobile按钮

时间:2011-05-25 14:02:06

标签: selenium jquery-mobile capybara

Capybara的Selenium驱动程序不会点击JQuery Mobile格式化按钮。它认为按钮不可见。

有没有人见过这个问题并绕过它?

我在这里创建了一个“绿地”应用程序来演示此问题: 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/fxdriver@googlecode.com/components/nsCommandProcessor.js:256:in `unknown'
    [remote server] file:///var/folders/fG/fGiEX6gLHQyvWGWb-5MpfU+++TI/-Tmp-/webdriver-profile20110525-21904-h3s00b/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:305:in `unknown'
    [remote server] file:///var/folders/fG/fGiEX6gLHQyvWGWb-5MpfU+++TI/-Tmp-/webdriver-profile20110525-21904-h3s00b/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:320:in `unknown'
    [remote server] file:///var/folders/fG/fGiEX6gLHQyvWGWb-5MpfU+++TI/-Tmp-/webdriver-profile20110525-21904-h3s00b/extensions/fxdriver@googlecode.com/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

3 个答案:

答案 0 :(得分:1)

尝试怎么样:

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

这适用于Selenium 2和jQuery mobile。

答案 1 :(得分:1)

Capybara的DOM轮询可能是在页面加载和非活动时(在jQueryMobile页面过渡效果完成之前)找到您的选择器。我通过如下方式确定我的选择器来解决这个问题:

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

have_selector将阻止脚本,直到页面处于活动状态。

答案 2 :(得分:0)

这听起来很熟悉,但我想我们可以通过将Selenium移到capybara-webkit来解决它:

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