检查文本是否为粗体

发布于 2025-01-17 02:57:23 字数 1422 浏览 0 评论 0原文

我正在测试搜索的输出,我想确保我会得到文本并且它会是粗体。 例如,我希望名称包含“ar”。作为输出,我将得到:在此处输入图像描述

但我想确保名称中包含“ar”,但在职位、部门等方面会忽略它。 片段的来源是:

<td style="width: 80%;">
                            <ul style="font-size: 20px;width: 50%;">
                                <li><b>Cecil Bonaparte</b></li>
                                <li style="font-size: 12px;">Software Engineer</li>
                                <li style="font-size: 12px;">Development</li>
                                        <li style="font-size: 12px;">HQ - CA</li>
                                <li style="font-size: 12px;">
                                    [email protected]                                </li>
                            </ul>
                        </td>

是否有一个选项可以检查元素是否具有文本并且该文本是否为粗体? 我当前的代码是:

$("[class=odd]").shouldHave(text("char"));

我的游乐场可以在 https://opensource-demo 找到.orangehrmlive.com/index.php/auth/login目录选项卡

I am testing the output of a search and I want to be sure that I will get the text and that it would be bold.
For example I want the name to include "ar". As an output I will get:enter image description here

But I want to be sure that I will have "ar" in name, but will ignore it in position, department, etc.
The source of the fragment is:

<td style="width: 80%;">
                            <ul style="font-size: 20px;width: 50%;">
                                <li><b>Cecil Bonaparte</b></li>
                                <li style="font-size: 12px;">Software Engineer</li>
                                <li style="font-size: 12px;">Development</li>
                                        <li style="font-size: 12px;">HQ - CA</li>
                                <li style="font-size: 12px;">
                                    [email protected]                                </li>
                            </ul>
                        </td>

Is there an option to check if an element has the text and this text is bold?
My current code is:

$("[class=odd]").shouldHave(text("char"));

My playground could be found at https://opensource-demo.orangehrmlive.com/index.php/auth/login , Directory tab

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

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

发布评论

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

评论(1

白云不回头 2025-01-24 02:57:23

我的解决方案如下。检查应用于文本的样式有点困难,但我们很幸运,因为 innerHtml() 方法将公开内联样式。我应该指出,不建议使用 innerHtml(),但我目前不知道一个合适的替代方案。

@Test
public void whatever() {
    // Open site and enter credentials
    open("https://opensource-demo.orangehrmlive.com/");
    $("#txtUsername").val("Admin");
    $("#txtPassword").val("admin123");
    $("#btnLogin").click();
    $("#menu_directory_viewDirectory").click();

    var searchTerm = "ar";

    $("#searchDirectory_emp_name_empName").val(searchTerm);
    
    // This click is required to cause the dropdown to lose focus
    $("#search_form").click();        
    $("#searchBtn").click();
    
    // Get the first entry from each row in the results table
    ElementsCollection resultTable = $("#resultTable tr li:first-child");

    for (SelenideElement searchResult : resultTable) {
        // Confirm each result has the expected search term
        searchResult.shouldHave(Condition.text(searchTerm));

        // Confirm each result has bold applied to the text
        assertThat(searchResult.innerHtml().substring(0, 3)).isEqualTo("<b>");
    }
}

My solution for this is below. It is a little difficult to check the styling applied to text but we are fortunate here as the innerHtml() method will expose the inline styling. I should point out that using innerHtml() is not recommended, but I currently do not know a decent alternative.

@Test
public void whatever() {
    // Open site and enter credentials
    open("https://opensource-demo.orangehrmlive.com/");
    $("#txtUsername").val("Admin");
    $("#txtPassword").val("admin123");
    $("#btnLogin").click();
    $("#menu_directory_viewDirectory").click();

    var searchTerm = "ar";

    $("#searchDirectory_emp_name_empName").val(searchTerm);
    
    // This click is required to cause the dropdown to lose focus
    $("#search_form").click();        
    $("#searchBtn").click();
    
    // Get the first entry from each row in the results table
    ElementsCollection resultTable = $("#resultTable tr li:first-child");

    for (SelenideElement searchResult : resultTable) {
        // Confirm each result has the expected search term
        searchResult.shouldHave(Condition.text(searchTerm));

        // Confirm each result has bold applied to the text
        assertThat(searchResult.innerHtml().substring(0, 3)).isEqualTo("<b>");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文