如何在Capybara中编辑日历输入元素
我目前正在尝试编辑一个日历输入元素并设置新日期。这是我想做的。
元素:
<input class="ant-calendar-input " placeholder="MM/DD/YYYY" value="03/01/2022">
XPATH:
/html/body/div[2]/div/div/div/div/div[1]/div/input
我的代码:
find("ant-calendar-input").set(value='01/01/2022')
我遇到了一个错误,Capybara无法找到此元素。
I'm currently trying to edit a calendar input element and set a new date. Here is what I'm trying to do.
Element:
<input class="ant-calendar-input " placeholder="MM/DD/YYYY" value="03/01/2022">
Xpath:
/html/body/div[2]/div/div/div/div/div[1]/div/input
My code:
find("ant-calendar-input").set(value='01/01/2022')
I'm getting an error that capybara is unable to find this element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为CSS选择器,“蚂蚁范围内输入”将寻找类型的'ant-calendar输入'的元素,而您显示的元素是类型为'输入'的元素,其中一类“ ant-calendar-Input”。有效的CSS选择器可以匹配该元素,
这是这样说的,您声称这是一个日历输入,但输入元素只是文本输入。我认为这意味着您使用的是某种绑定到
Input
元素的JS小部件,因此可能隐藏了原始输入。如果是这种情况,那么您需要与小部件生成的元素进行交互(就像用户必须这样),而不是直接与输入元素进行交互"ant-calendar-input" as a CSS selector would look for an element of type 'ant-calendar-input' whereas the element you show is of type 'input' with a class of 'ant-calendar-input'. A valid CSS selector to match that element would be something like
That being said, you claim this is a calendar input, but the input element is just a text input. I assume this means you are using some type of JS widget that is bound to the
input
element and therefore may have hidden the original input. If that's the case then you'll need to interact with the elements generated by the widget (like a user would have to) rather than directly with the input element