Testcafe:如何创建选择器来选择 HTML 标记之外的时间戳? <strong>时间戳:</strong> 12/13/2023 10:55 A.M.美国东部时间

问题描述 投票:0回答:1

我是 TestCafe 的新手。

下面是示例 HTML 代码,当我创建带有 id 的选择器时,它仅返回“当前时间戳:”,并且我需要当前时间的时间戳。

Page object file:

import { Selector } from 'testcafe';

class page {
lastUpdateTimeStamp = Selector('#timestamp_label');

export default new page();
<div _ngcontent-ww-123="" class="div-group">
      <strong _ngcontent-ww-123="" id="timestamp_label">Current Timestamp:</strong>
                  12/13/2023 10:55 A.M. EST
    </div>

尝试使用下面的选择器:

lastUpdateTimeStamp = Selector('#timestamp_label');


Returned value of only text "Current Timestamp:" 

Expecting Current Timestamp: 12/13/2023 10:55 A.M. EST
selector testcafe
1个回答
0
投票

出现此问题的原因在于您创建选择器的方式。

lastUpdateTimeStamp = Selector('#timestamp_label');

在您的示例中,您仅选择“strong”html 元素。但是,为了选择“当前时间戳:12/13/2023 10:55 A.M.” EST',您需要选择作为两个文本的父元素的元素。在示例中,它是 class="div-group" div。因此,以下选择器应该可以解决该问题:

lastUpdateTimeStamp = Selector('.div-group');

© www.soinside.com 2019 - 2024. All rights reserved.