WebUI.getText()返回空字符串

street_耶稣

我想获取我的TestObject的文本,我使用WebUI.getText()。我的代码在我的一个页面上工作正常,但在另一个页面上失败。我不知道为什么会失败,从字面上看都是一样的,它也不应该失败。这就是我在做什么:

    @Keyword
public boolean verifyIPAddr(Socket socket){
    //create test object for the ip header
    TestObject ipHeader =  new TestObject().addProperty("id", ConditionType.EQUALS, 'ipaddr-in-header')
    WebUI.waitForElementPresent(ipHeader, 20, FailureHandling.OPTIONAL)

    //get text (IP) from ipHeader
    String ipHeaderStr = WebUI.getText(ipHeader)
    KeywordUtil.logInfo("ipHeaderStr: " + ipHeaderStr.toString())
    //split the ipHeaderStr so that "IP: " portion can be removed and only "0.0.0.0" portion is left 
    String[] ipHeaderStrArr = ipHeaderStr.split(' ')
    //store the ip in a variable
    String guiIPAddress = ipHeaderStrArr[1]

    //get the socket side ip
    String cassetteIP = socket.getInetAddress().getHostAddress()
    KeywordUtil.logInfo(" address:" + cassetteIP)

    //validate that both are the same
    if(cassetteIP.equals(guiIPAddress)){
        KeywordUtil.logger.logPassed(guiIPAddress + " IP from GUI matches: " + cassetteIP + " from socket")
        return true;
    }
    else{
        KeywordUtil.logger.logFailed(guiIPAddress + " IP from GUI does not match: " + cassetteIP + " IP from socket")
         return false
         }
}

堆栈跟踪[![] [1]] 2

我是100%的人,它与WebUI.getText()有关,但它使我感到困惑,因为它适用于一个页面,但不适用于另一个页面。

以下是工作页面的HTML: 的HTML

以下是无法使用的页面的HTML:

HTML2

更新:

我只是注意到发生故障的设备有时会失败,有时甚至会过去,我仍然想知道如何保证行为保持稳定。

伴侣Mrše

您可以尝试以下几种方法:

  1. 您可以在获取元素的文本之前添加延迟:
WebUI.delay(30)
  1. 你可以等一下
WebUI.waitForElementPresent(ipHeader, 60, FailureHandling.OPTIONAL)

原因是,Katalon(硒)代码通常取决于其影响范围之外的元素,例如加载时间,网络流量,计算机硬件,竞争性竞争条件等。

因此,即使使用相同的代码,有时等待时间也会有所不同,这就是为什么最好使用灵活的等待(例如waitForElement*()方法)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章