Selenium 找不到类型为 number 的字段 [英] Selenium can't find fields with type number

查看:19
本文介绍了Selenium 找不到类型为 number 的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在让 Cucumber 使用 HTML5 type="number" 查找字段时遇到问题.我不太喜欢它们在浏览器中的外观,但我有一些字段需要移动设备上的数字键盘,这似乎是最简单的方法.我正在使用 SimpleForm 构建表单,当我设置 :as =>:text 一切正常,但如果我设置 :as =>:number,字段不会被填写.我没有收到任何错误,只是没有填写该字段.

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 fields that need the number keyboard on mobile, and this seems to be the easiest way to get it. I'm using SimpleForm to build forms and when I set :as => :text everything works, but if I set :as => :number, the fields don't get filled out. I don't get any error, the field just doesn't get filled.

具体来说,当我有这样的步骤时:

To be specific, when I have a step like this:

And I fill in "application_form_age" with "52"

那么这个标签就不会被填写:

then this tag won't get filled in:

<input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number">​

但这一个有效:

<input class=​"string required" id=​"application_form_age" name=​"application_form[age]​" size=​"50" type=​"text">​

而且,它只发生在@javascript 场景中.在不需要@javascript 并且场景不启动浏览器的情况下,这也可以正常工作.

Also, it only happens in @javascript scenarios. In situations where @javascript isn't necessary and the scenario doesn't launch a browser, that works fine too.

事物的版本:

capybara (2.2.1)
cucumber (1.3.14)
selenium-webdriver (2.41.0)
simple_form (2.1.1)
webrat (0.7.3)

Firefox 29.0

我被难住了.我尝试抽出一堆我的应用程序 JS 和 CSS,看看我正在做的事情是否破坏了它,但没有运气.我只是通过强制这些字段在我的测试环境中没有 HTML5 类型号来修补它,但我不想那样生活.还有人看到这个吗?我找不到任何对它的引用,这使它看起来像是我正在做的事情.但我一直无法弄清楚.

I'm stumped. I tried yanking out a bunch of my application JS and CSS to see if something I'm doing is breaking it, but no luck with that. I'm just patching it out by forcing those fields not to have HTML5 type number in my test environment, but I don't want to live like that. Is anyone else seeing this? I haven't been able to find any references to it, which makes it seem like it's something I'm doing. But I haven't been able to figure it out.

推荐答案

首先,我认为您对这些框架有些困惑.Cucumber 是一个 BDD 框架,它不会以任何方式自动化浏览器,所以这个问题与它无关(这就是我从你的问题标题中删除它的原因).

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).

看起来您正在使用 Capybara,它是一个 ATDD 框架.您可能会考虑向我们展示您用来诊断问题的 Capybara 代码.

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.

在后台,我假设您使用 Selenium WebDriver,我可以确认 Selenium 可以与 <input type="number"> 一起正常工作(使用 Firefox 28 测试,这是唯一的 selenium-webdriver (2.41.0) 支持).

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')

因此,您可能希望使用 Capybara 创建一个类似的演示来测试此功能.

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

如果演示有效,那么我们需要仔细查看您的应用程序.否则,请为 Capybara 开发者开张票.

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

这篇关于Selenium 找不到类型为 number 的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆