automated-tests - 使用 Microsotf UFT 单击 Web 元素的子级 Web 按钮

标签 automated-tests hp-uft uft14 uft-api

我目前正在为网络客户端开发测试自动化策略。在此 Web 客户端上,所有 Web 元素都有一个用于标识对象的 data-testid。 不幸的是,在某些情况下,数据测试ID不是唯一的,因此不可能清楚地识别对象,我无法更改这些数据测试ID。 因此,我尝试编写一个组件,它根据 data-testid 标识一个 web 元素,然后按下该元素的子元素按钮。 不幸的是我的代码不起作用,因为UFT无法识别我的对象,不幸的是我无法自己找到解决方案。 该元素的 HTML 如下所示: HTML code of the specific part

我想查找数据测试 ID 为“Orderbeleg_Segmentumbuchung”的 Web 元素,然后单击其数据测试 ID 为“add:b”的子元素。

这是我写的代码:

Option Explicit

Dim bcName
bcName = "Webbuttonclick_add"
'--------------------------------------------------------------------------------------------- 

Dim pDoit, pParent, var, debug1
pParent = Parameter("parent")
pDoit = CBool(evalVarAndOffset(Parameter("doit")))
var = "data-testid:= .*" & pParent &".*"

If pDoit = True Then
   Browser("index:=0").Page("index:=0").WebElement(var).Click
   If Browser("index:=0").Page("index:=0").WebElement(var).exist(1) Then
        Browser("index:=0").Page("index:=0").WebElement(var).ChildItem("data-testid:= 
        add:b").Click
        wait 1
   End If
End If

SQS_ActionFinish

var 是父元素的 data-testid。

最佳答案

通过阅读这个问题,我看到了一些事情(我实际上并没有尝试运行代码,所以请检查我是否正确)。

  • 您正在使用 data-testid 作为测试对象属性。我认为这不起作用,因为 UFT 没有定义此属性。尝试attribute/data-testid (further reading)。
  • 您不需要使用 ChildItem,您可以将 WebElement 直接嵌套在 var 元素下。您可以使用 WebElement as a container即使 UFT 默认情况下不这样做。事实上ChildItemTable 特定方法,如果您的意思是 ChildObjects ,则不适用于此处。那么参数应该是 Description 对象,而不是内联描述的字符串。
  • var 中,第一个 .* 之前有一个空格,这是故意的吗?

要总结我的评论,请尝试以下操作:

Browser("index:=0").Page("index:=0").WebElement("属性/data-testid:=.*"&pParent&".*").WebElement("属性/data-testid:=add:b").点击

关于automated-tests - 使用 Microsotf UFT 单击 Web 元素的子级 Web 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73373127/

相关文章:

hp-uft - 无法识别 Chrome 浏览器中的任何对象

testing - 在机器人框架中以毫秒为单位获取时间的关键字是什么?

vbscript - 如何在使用 UFT/QTP 时放大或缩小网页

excel - 使用 VBscript 在 Excel 中搜索并替换多个字符

excel - VBscript中关键字的大量参数管理

hp-uft - 启动 UFT 应用程序会使 Cortana 使用更多 CPU 并且 react 更慢

javascript - 如何使用 WebdriverIO 返回一个新的有效页面对象?

android - 升级到Android Studio 1破坏了Robolectric测试

ruby-on-rails - 无法在 60 秒内获得稳定的 Firefox 连接 (127.0.0.1 :7055)