如何用水豚填写本地时间字段? [英] How to fill in a datetime-local field with capybara?

查看:83
本文介绍了如何用水豚填写本地时间字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cocoon添加记录。 ID类似于 workshop_instance_sessions_attributes_1477654140_start_time 。目前,我正在遍历DOM并获取了动态生成的ID(这很好用),因此我可以使用它们来引用输入内容进行填充。我尝试了很多事情(许多可以在控制台中工作),但似乎仍然无法获得工作规范。以下是我尝试过的一些选择( first 是保存id的变量,而 @time 基本上是时间。现在,它会随着块的执行而增加)。

I am using Cocoon to add records. IDs look like workshop_instance_sessions_attributes_1477654140_start_time . At the moment I am traversing the DOM and grabbing the dynamically generated IDs (this works fine) so I can use them to reference the input to fill in. I have tried many things (many that work in console) and still cannot seem to get the spec to work. Below are a selection of things I've tried (first is the variable which holds the id and @time is basically Time.now that increments as a block executes).

在控制台中工作:

page.evaluate_script( document.getElementById('#{first}')。value ='#{@ time.strftime('%Y-%m-%eT%H:%M')}'')

page.evaluate_script( $('## {first}')。val('#{@ time。 strftime(%Y-%m-%eT%H:%M)}'))

在控制台:

首先填充,使用:@ time.strftime(%Y-%m-%eT%H:%M)

find( ## {first})。set(@ time.strftime(%Y-% m-%eT%H:%M))

这些都已经在一个小块内(我遇到的一个常见问题)我知道工作正确,因为第一个变量已正确设置。

These are all already within a within block (a common issue I run into) that I know is working correct as the first variable is being correctly set.

作为参考,我的html看起来像这样:

As reference my html looks like this:

< input class =表单控件 type = datetime-local name = workshop_instance [sessions_attributes] [1477655024] [start_time] id = workshop_instance_sessions_attributes_1477655024_start_time>

任何有关如何使此规范生效的指针将不胜感激。

Any pointers on how to get this spec to work would be much appreciated.

推荐答案

根据Capybara发行说明此处

According to the Capybara release notes here:


Selenium驱动程序在填写日期/时间/日期时间本地输入时支持日期/时间

Selenium driver supports Date/Time when filling in date/time/datetime-local inputs

所以回答您的问题:

fill_in first, with: Time.new(2018, 01, 02, 12)

这篇关于如何用水豚填写本地时间字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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