如何在Capybara中编辑日历输入元素

发布于 2025-02-03 12:36:31 字数 373 浏览 3 评论 0原文

我目前正在尝试编辑一个日历输入元素并设置新日期。这是我想做的。

元素:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪是无色的血 2025-02-10 12:36:31

作为CSS选择器,“蚂蚁范围内输入”将寻找类型的'ant-calendar输入'的元素,而您显示的元素是类型为'输入'的元素,其中一类“ ant-calendar-Input”。有效的CSS选择器可以匹配该元素,

find('input.ant-calendar-input').set('01/01/2022')

这是这样说的,您声称这是一个日历输入,但输入元素只是文本输入。我认为这意味着您使用的是某种绑定到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

find('input.ant-calendar-input').set('01/01/2022')

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文