Submit button is being clicked, but seems to be stopping action

Hi community! This test has been working fine previously, but a few days ago the click method doesn’t seem to be working with this particular button. After entering credentials, you’re prompted for a 2FA, so when you click submit, the button is clicked, and you’ll be able to see on the gif, the action is perfomed and seems to be loading, but then it stops.

ezgif.com-gif-maker (1)

This is the html of the button. I tried with different locators (from the div and the label), IDs are dynamic, so I used xpath or different combination of selectors, using both the Click method form Katalon and also with JavaScript executor, but nothing worked. Same result in both cases

button html

These are both the pieces of code I tried with Click:

WebUI.waitForElementClickable(findTestObject('NSVerificationPage/btnSubmit'), 20)

WebUI.click(findTestObject('NSVerificationPage/btnSubmit'))

JS Executor

WebUI.waitForElementClickable(findTestObject('NSVerificationPage/btnSubmit'), 20)

WebDriver myDriver = DriverFactory.getWebDriver();

WebElement submitBtn = myDriver.findElement(By.xpath('//*[(contains(text(), "Submit") or contains(., "Submit")) and @class = "n-w-label n-widget style-button n-widget--status-none n-w-button__label n-w-text-style--wrap-truncate"]'));

JavascriptExecutor executor = (JavascriptExecutor)myDriver;

executor.executeScript("arguments[0].click();", submitBtn);

This is my first time posting here, so not sure if any other infor is needed. If anyone has any suggestion, I’d greatly appreciate it.

1 Like

Try this:

String js = 'document.querySelector("#n-id-component-51").click()'
WebUI.executeJavaScript(js, null)
1 Like

Hi, thanks for the reply! I just tried that solution, but unfortunatelly it’s still giving me same result.

1 Like

The code I gave you will click the HTML <div> element with that id. To click the <label> element instead, try this:

String js = 'document.querySelector("#n-id-component-57").click()'
WebUI.executeJavaScript(js, null)

If that doesn’t work, then you might not be addressing the correct element. To prove the point, bring up the page in the browser and enter the following in the browser console:

document.querySelector("#n-id-component-57").click()
1 Like

So, I also tried with the second piece of code you sent, but nothing changed.
When testing that on the browser console as you mentioned, it seems it’s correctly being clicked, because this alert showed up (there were no values on the field). Unless I’m not understanding the result the way it should be.
alert

Could it be something related to the page itself? I also tried looking at the dev console while running the test, but didn’t see anything unsusual, though I don’t know exactly what to look at either

1 Like

Ah, wait… I missed that.

Try this:

String selector = "div[aria-label=Submit] > label:nth-of-type(1)"
String js = "document.querySelector('${selector}').click()"
WebUI.executeJavaScript(js, null)

Take care to copy the quotes correctly - I had to switch them around to pull in the ${selector} variable.

Here is the code to try in the browser console:

document.querySelector("div[aria-label=Submit] > label:nth-of-type(1)").click()

If it fails, put single-quotes around ‘Submit’

1 Like

First, thank you so much for taking the time to provide help. Using the code just as you wrote it, it’s still behaving the same way the rest of the previous attempts. If I add the single quotes to Submit, it throws me an exception “javascript error: missing ) after argument list”

Test Cases/Steps/NS_Login FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$6.call(Unknown Source)
at NS_Login.run(NS_Login:51)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1663355301433.run(TempTestCase1663355301433.groovy:23)
Caused by: org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list
(Session info: chrome=105.0.5195.125)
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘EZE1-LLN-B03024’, ip: ‘192.168.0.137’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 105.0.5195.125, chrome: {chromedriverVersion: 104.0.5112.79 (3cf3e8c8a07d…, userDataDir: C:\Users\GISELE~1.ALB\AppDa…}, goog:chromeOptions: {debuggerAddress: localhost:50189}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: efefd1b51bfbd669c2205d070498b6ed
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:19)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:489)
at org.openqa.selenium.support.events.EventFiringWebDriver.lambda$new$1(EventFiringWebDriver.java:105)
at com.sun.proxy.$Proxy8.executeScript(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.executeScript(EventFiringWebDriver.java:229)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.doCall(ExecuteJavascriptKeyword.groovy:48)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.call(ExecuteJavascriptKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 17 more

1 Like

Does it work in the browser console?

1 Like

What I noticed is that if there are no values on the field and run that script on the console, the alert of the image above shows up. Now if I enter a value (no matter if it’s a valid code or not) and run that script, the button is clicked but the action stops, just as all the other methods I tried

1 Like

It’s entirely possible the page (the application) is using JavaScript to perform specific actions based on current page state. It’s your task to find out what those actions might be (it’s impossible for me to know what they might be).

Hint: Try your best to make your test script mimic the actions of a user. Said another way, don’t do things a user cannot do.

1 Like

Hi there! After investigating and digging into why the click didn’t work, I realized the computer’s time was a few minutes off and since I’m using an OTP generator for the login, that was the reason it was causing issues. When the code was being generated it didn’t match the time on the computer, after syncing the clock with windows servers the tests worked fine!

I would have never guessed that was messing with my tests. I appreciate the time you took into provinding solutions

1 Like