Selenium can't find fields with type number

前端 未结 2 1034
迷失自我
迷失自我 2021-01-23 17:52

I\'m having a problem getting Cucumber to find fields with the HTML5 type=\"number\". I\'m not a big fan of the way they look in the browser, but I have a few field

相关标签:
2条回答
  • 2021-01-23 18:44

    Ok, I have found firefox has an option to disable number input field support: 'dom.forms.number'.

    So if you add the following lines in your env.rb, number input gets disabled and tests work again.

    Capybara.register_driver :selenium do |app|
      profile = Selenium::WebDriver::Firefox::Profile.new
      profile["dom.forms.number"] = false
      Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
    end
    
    0 讨论(0)
  • 2021-01-23 18:50

    First off, I think you have some confusion regarding those frameworks. Cucumber is a BDD framework, which doesn't automate browsers in any way, so this question has nothing to do with it (This is why I removed it from your question title).

    Looks like you are using Capybara, which is an ATDD framework. You might probably consider showing us the Capybara code you use in order diagnose your problem.

    Under the hood, I assume you use Selenium WebDriver, I can confirm that Selenium works fine with <input type="number"> (Tested with Firefox 28, which is the one selenium-webdriver (2.41.0) supports to).

    require 'selenium-webdriver'
    
    driver = Selenium::WebDriver.for :firefox
    
    DEMO_PAGE = <<-eos
      data:text/html,
      <input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number">
    eos
    
    driver.get(DEMO_PAGE)
    driver.find_element(:tag_name, 'input').send_keys('25')
    

    So you might want to create a similar demo using Capybara to test this functionality.

    If the demo works, then we need take a closer look at your application. Othwewise, please raise a ticket for Capybara developers.

    0 讨论(0)
提交回复
热议问题