【问题标题】:Robot Framework doesn't find element correctly by xpathRobot Framework 无法通过 xpath 正确找到元素
【发布时间】:2021-02-07 18:10:35
【问题描述】:

机器人框架不通过 xpath 识别元素。

下面是代码

<div id="sticky-actions-sticky-wrapper" class="sticky-wrapper" style="height: 100px;"><section class="content-header" id="sticky-actions" style="">
    <h1>Curriculum</h1>

    <div class="breadcrumb save-message hidden">
        <label class="text-success">
            <i class="flaticon flaticon-circle-check"></i>
            Saved <span>a few seconds ago</span>
        </label>
    </div>

    <div class="row p-t-15">
        <div class="col-xs-12">
            <button type="button" class="btn btn-primary add-task-btn" disabled="">Create New Task</button>

            <div class="btn-group m-r-15">
                <button type="button" class="btn btn-primary dropdown-toggle add-statement-btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="">
                    Create <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li><a tabindex="0" class="add-curriculum-btn">Curriculum</a></li>
                    <li><a tabindex="0" class="add-learning-area-btn hidden">Learning Area</a></li>
                    <li><a tabindex="0" class="add-topic-btn hidden">Topic</a></li>
                    <li><a tabindex="0" class="add-outcome-btn hidden">Outcome</a></li>
                </ul>
            </div>

            <button type="button" class="btn btn-circle btn-xs blue link-statements-btn" disabled="" data-toggle="tooltip" data-placement="top" title="" data-original-title="Link selected statements">
                <i class="fa fa-link"></i>
            </button>
        </div>
    </div>
</section></div>

我用来查找“创建”按钮的 Xpath:

xpath=//*[@id="sticky-actions-sticky-wrapper"]/div[2]/div/div/button

xpath=//*[@id="sticky-actions"]/div[2]/div/div/button[.//text() = 'Create']

机器人框架步骤:

click element  xpath=//*[@id="sticky-actions-sticky-wrapper"]/div[2]/div/div/button

错误:-

ValueError: Element locator 'xpath=//*[@id="sticky-actions-sticky-wrapper"]/div[2]/div/div/button' did not match any elements.

【问题讨论】:

  • 你能检查是否有任何框架,因为定位器看起来不错你也可以放一些等待函数来找到这个元素

标签: xpath robotframework


【解决方案1】:

根据您的 XML,第一个 div 内有一个 section 元素,您没有将其包含在 XPath 中。如果你添加它应该可以工作:

//*[@id="sticky-actions-sticky-wrapper"]/section/div[2]/div/div/button

//*[@id="sticky-actions"]/div[2]/section/div/div/button[.//text() = 'Create']

【讨论】:

    猜你喜欢
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 2021-03-27
    • 2019-11-19
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多