Using Chrome verifyElementAttributeValue fails before page change

I have tests where I call WebUI.click followed by WebUI.verifyElementAttributeValue. These tests are several years old and have work until recently. Now when run with the Firefox browser, the test work as expected. When the same tests are run with the Chrome browser, the tests fail. WebUI.click clicks a button/link successfully. When test run with Chrome browser, WebUI.verifyElementAttributeValue fails. It fails because it checks the page that the button was clicked on. It doesn’t check after the page has changed because of the previous WebUI.click

Is there a fix specific to Chrome or is this known problem with the driver that I need to wait for?

My version of Katalon, ChromeDriver, Chrome browser are the latest.

OS: Windows 10
Katalon: 8.6.10.208
Chrome: 139.0.7258.128
ChromeDriver: 139.0.7258.68
Delay between actions: 300ms

WebUI.click(findTestObject(‘button_cancel’))
WebUI.verifyElementAttributeValue(findTestObject(‘common/meta_application’), ‘data-screenid’, ‘screen002’, 20)

2 Likes

After the click and before the verify, you should make sure that the new page is firmly loaded. In order to do that, you can insert a wait. For example,

WebUI.click(findTestObject(‘button_cancel’))
WebUI.waitForElementPresent(findTestObject(‘common/meta_application’), 10)
WebUI.verifyElementAttributeValue(findTestObject(‘common/meta_application’), ‘data-screenid’, ‘screen002’, 20)

Just for your reference, I would quote the source code of verifyElementAttributeValue() method of the com.kms.katalon.core.webui.keyword.builtin.VerifyElementAttributeValueKeyword class.

    @CompileStatic
    public boolean verifyElementAttributeValue(TestObject to, String attributeName, String attributeValue, int timeOut, FailureHandling flowControl) {
        WebUIKeywordMain.runKeyword({
            boolean isSwitchIntoFrame = false
            try {
                WebUiCommonHelper.checkTestObjectParameter(to)
                logger.logDebug(StringConstants.COMM_LOG_INFO_CHECKING_ATTRIBUTE_NAME)
                if (attributeName == null) {
                    throw new IllegalArgumentException(StringConstants.COMM_EXC_ATTRIBUTE_NAME_IS_NULL)
                }
                timeOut = WebUiCommonHelper.checkTimeout(timeOut)
                isSwitchIntoFrame = WebUiCommonHelper.switchToParentFrame(to, timeOut)
                WebElement foundElement = WebUIAbstractKeyword.findWebElement(to, timeOut)
                if (foundElement.getAttribute(attributeName) != null) {
                    if (foundElement.getAttribute(attributeName).equals(attributeValue)) {
                        logger.logPassed(MessageFormat.format(StringConstants.KW_LOG_PASSED_OBJ_X_ATTRIBUTE_Y_VALUE_Z, to.getObjectId(), attributeName, attributeValue))
                        return true
                    } else {
                        WebUIKeywordMain.stepFailed(
                                MessageFormat.format(
                                StringConstants.KW_LOG_FAILED_OBJ_X_ATTRIBUTE_Y_ACTUAL_VALUE_Z_EXPECTED_VALUE_W,
                                to.getObjectId(), attributeName, foundElement.getAttribute(attributeName), attributeValue), flowControl, null, true)
                        return false
                    }
                }  else {
                    WebUIKeywordMain.stepFailed(MessageFormat.format(StringConstants.KW_LOG_FAILED_OBJ_X_HAS_ATTRIBUTE_Y, [to.getObjectId(), attributeName] as Object[]), flowControl, null, true)
                    return false
                }
            } catch (WebElementNotFoundException ex) {
                WebUIKeywordMain.stepFailed(MessageFormat.format(StringConstants.KW_LOG_WARNING_OBJ_X_IS_NOT_PRESENT, to.getObjectId()), flowControl, null, true)
            } finally {
                if (isSwitchIntoFrame) {
                    WebUiCommonHelper.switchToDefaultContent()
                }
            }
            return false
        }, flowControl, RunConfiguration.getTakeScreenshotOption(), (to != null) ? MessageFormat.format(StringConstants.KW_MSG_CANNOT_VERIFY_OBJ_X_ATTRIBUTE_Y_VALUE_Z, to.getObjectId(), attributeName, attributeValue)
        : StringConstants.KW_MSG_CANNOT_VERIFY_OBJ_ATTRIBUTE_VALUE)
    }

As you can see, the method can potentially emit 3 types of message string for StepFailedException.

  1. StringConstants.KW_LOG_WARNING_OBJ_X_IS_NOT_PRESENT
  2. StringConstants.KW_LOG_FAILED_OBJ_X_HAS_ATTRIBUTE_Y
  3. StringConstants.KW_LOG_FAILED_OBJ_X_ATTRIBUTE_Y_ACTUAL_VALUE_Z_EXPECTED_VALUE_W

Which message did you find in the log when you run your test?

With the message type identified, you will have better idea what’s going on.

2 Likes

Thanks for the response. This is frustrating. These tests are not new and have been working in the past. Now again I am needing to go back and change tests that once worked because of some unknown change outside my control.

1 Like

Are you aware how you should change your tests so that they pass in the new environment?

Or are you unsure how to change your tests yet?

1 Like

Hi @Clayton_Friesen,

Have you solved your issue yet? If yes, please feel free to share your solution. If no, feel free to provide more information or we will proceed to close this thread. Thank you