如何按课堂和文本的一部分选择一个元素?

发布于 2025-01-20 11:46:24 字数 524 浏览 2 评论 0原文

对于日历,我将其设置为此:

<div class="Calendars__day___1LZkL">1</div>
<div class="Calendars__day___1LZkL">2</div>
<div class="Calendars__day___1LZkL">3</div>
<div class="Calendars__day___1LZkL">4</div>

等等。我想按班级名称和文字选择日历日,但不知道如何使其正常工作。

我目前有这样的函数设置:

    calendarDay(day) {
        return $(`[class^="Calendars__day"][text()="${day}"]`);
    }

但这引发了一个错误“无效的选择器:无效的选择器:指定了无效或非法选择器“

我正在使用wdio来运行自动化,这就是选择器的目的

For a calendar, I have it setup as this:

<div class="Calendars__day___1LZkL">1</div>
<div class="Calendars__day___1LZkL">2</div>
<div class="Calendars__day___1LZkL">3</div>
<div class="Calendars__day___1LZkL">4</div>

and so on. I want to select the calendar day by class name and text but can't figure out how to get it to work.

I currently have a function setup like this:

    calendarDay(day) {
        return $(`[class^="Calendars__day"][text()="${day}"]`);
    }

but this throws an error "invalid selector: invalid selector: An invalid or illegal selector was specified"

I'm using WDIO to run automation and that is what the selector is for

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

孤独患者 2025-01-27 11:46:24

弄清楚了,要使用的有效选择器是:

$(`//div[contains(@class, "Calendars__day") and contains(., ${day})]`);

Figured it out, the selector to use that works is:

$(`//div[contains(@class, "Calendars__day") and contains(., ${day})]`);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文