【问题标题】:Need xpath to locate button whose id is dynamic how to click that using in RobotFramework automation script需要xpath来定位id是动态的按钮如何在RobotFramework自动化脚本中使用
【发布时间】:2015-02-25 07:46:56
【问题描述】:

下面的代码会在点击它时给我一个“+”符号会出现一个弹出窗口,我尝试使用 xpath 来找到它,但它没有工作,请帮助我解决这个问题。

我正在使用机器人框架

<div id="button-1571" class="x-btn x-box-item x-toolbar-item x-btn-default-toolbar-small x-icon x-btn-icon x-btn-default-toolbar-small-icon" style="border-width: 1px; left: 373px; margin: 0px; top: 6px;">

    <em id="button-1571-btnWrap">
        <button id="button-1571-btnEl" class="x-btn-center" autocomplete="off" role="button" hidefocus="true" type="button" style="height: 16px;">
            <span id="button-1571-btnInnerEl" class="x-btn-inner" style="margin: -1px 0px;"></span>
            <span id="button-1571-btnIconEl" class="x-btn-icon icon-plus"></span>
        </button>
    </em>

</div>

这是我尝试过的代码 点击按钮 xpath=//div[contains(@class, 'x-btn x-box-item x-toolbar-item x-btn-default-toolbar-small x-icon x-btn-icon x-btn-default- toolbar-small-icon')]/descendant::button[contains(@class, 'x-btn-center')]/span[contains(@class, 'x-btn-icon icon-plus')]

【问题讨论】:

  • 请使用 xpath : //*[@id="button-1571-btnEl"]
  • 我也试过了,但没用……错误是元素没有出现……你能建议一些其他的解决方案吗?
  • 这样使用:By.xpath("//*[@id='button-1571-btnEl'] "我做了一点改动。在引号中。
  • @HelpingHands:标题说按钮的 ID 是动态的。
  • @LarsH - 是的,但 xpath 有助于找到动态值/元素,对吧?

标签: selenium xpath robotframework


【解决方案1】:

请针对 RobotFramework 问题提出另一个问题。 关于定位您可以在 Xpath 下使用的 Web 元素的问题,它将为您工作。

下面的代码将点击 Web 元素。

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='x-btn x-box-item x-toolbar-item x-btn-default-toolbar-small x-icon x-btn-icon x-btn-default-toolbar-small-icon']/em/button/span[@class='x-btn-icon icon-plus']"))).click();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 2020-03-01
    • 2011-11-24
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2020-07-16
    相关资源
    最近更新 更多