首页 > 解决方案 > Katalon IDE 生成的脚本在 Eclipse 中出现错误

问题描述

脚本2

我正在使用 Katalon IDE 生成脚本。

由于我的应用程序在右上角有一个退出按钮,当我单击它时,IDE 将生成

xpath=(.//*[normalize-space(text()) and normalize-space(.)='S'])[3]/following::span[3]

在 Eclipse 中运行它时,此行会出错。在检查这个元素时,我发现了这个:


    <td id="titlebar_hyperlink_8-co_0" role="presentation" 
    nowrap="nowrap" align="left" class="  verticalSpacer" 
    style="vertical-align:top;">
    <span id="titlebar_hyperlink_8-lbsignout" align="left" 
    ctype="label" tabindex="0" targetid=
    "titlebar_hyperlink_8-lbsignout" mxevent="click" accesskey="S" 
    class="text powerwhite   anchor" style="display:block;cursor:pointer;" 
    title="Sign Out ALT+S" hotkey="83"><img id="titlebar_hyperlink_8- 
    lbsignout_image" src="btn_signout.gif" class="pwimg" border="0" 
    style="vertical-align:top;margin:0px;margin-left:3px;margin-right:3px;" 
    alt="Sign Out ALT+S"><span><span></span><span class="text hl 
    hlak">S</span><span>ign Out</span></span></span></td>

我是硒及其所有相关内容的新手。我将不胜感激任何形式的帮助。谢谢,堆栈溢出社区。

检查 Signout 元素

标签: eclipseseleniumxpathkatalon-studiokatalon-recorder

解决方案


尝试将 xpath 更改为

'.//*[@title="Sign Out ALT+S"]'

解释:

您想要唯一地定位一个元素。通常,您会尝试使用id,但元素的 id 似乎是动态的,因此它可能并非在所有情况下都有效。

*- 这意味着任何元素,并且在括号内[ ]放置要查找元素的属性。我选择标题是因为它在给定页面上可能是唯一的。

我推荐这个备忘单作为 xpath 参考。


推荐阅读