Element Not Interactable in a certain test case

Hi all, you daily questioner here.

So I am having a problem whereby I have an element that is not Interactable in a certain test case but interactable in other, using the exact same web object. This problem is pertaining to the last step, setText.

For clarity, the xpath used for this Test Object is: //input[@id=‘VerificationOTP’]

My question is really, how can I make it work in the second case where it currently isn’t working, as I need to be working with the incognito tab

The case where it works, has the following code.

firstName = 'Interview'
surname = 'Selection12'
email = 'InterviewSelection12@gmail.com'
passportNumber = 'Interview12!'

// Basic Personal Information Step
// Opens the Chrome Browser
WebUI.openBrowser('')

// Navigates the Chrome Browser to the Staging Environments Enrolment Workflow
WebUI.navigateToUrl('https://inscape-operations-staging.stratusolvecloud.com/App/Student/Workflow/NewEnrolment/2022')

// Maximizes the Window
//WebUI.maximizeWindow()

// Enters the First Name
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Welcome to INCONNECT - our online stu_0eecac'),
	firstName)

// Enters the Last Name
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Welcome to INCONNECT - our online stu_d2ddfb'),
	surname)

// Enters the Cell Phone Number: This is not validated, so it can always be the same
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_land Islands_cell'),
	'0790000000')

// Enters the Email Address: This is validated, it has to be unique
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Valid_c3'),
	email)

// Country of Origin Selection of South Africa
WebUI.selectOptionByValue(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/select_Country of OriginSouth AfricaUnited _72b9c5'),
	'1', false)

// ID Type Selection of Passport Number
WebUI.selectOptionByValue(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/select_--Select ID Type--RSA ID NumberPassp_e4a2f7'),
	'2', false)

// Enters the Passport Number: This is validated, it has to be unique
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Valid_c7'),
	passportNumber)

// Enters the Password
WebUI.setEncryptedText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Valid_c4'),
	'p4y+y39Ir5PEPmX20UxFKw==')

// Enters the Confirm Password
WebUI.setEncryptedText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_A digit (0-9) is required_c5'),
	'p4y+y39Ir5PEPmX20UxFKw==')

// Clicks the "Next" Button
WebUI.click(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/button_Next'))

// Sets the OTP from the Noted Feedback as a variable "OTP"
OTP = WebUI.getText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/span_6031'))

// On the modal, enters the OTP by pasting the OTP variable that it stored
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Please check your junk mail folder if_d47c1f'),
	OTP)

However, following the same steps but using a different method where I am opening 1 normal chrome and 1 incognito chrome, it doesn’t find the element to setText. Apologies for the long code. This method of opening chrome windows works, I have been using it during the day. My only problem is that for some reason, the element that works in the first case doesn’t work in the second case, using the exact same Test Object. Maybe I can dynamically create a test object for the input field to set the text? I just don’t know how to do it.

I have added a screenshot of the field where the OTP should be entered (Verification Code here), a screenshot of the error, and of the HTML for good measure if that helps.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

import org.openqa.selenium.chrome.ChromeDriver as ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions as ChromeOptions
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.Dimension
import org.openqa.selenium.Point
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import com.kms.katalon.core.testobject.ConditionType

firstName = 'Interview'
surname = 'Selection12'
email = 'InterviewSelection12@gmail.com'
passportNumber = 'Interview12!'

// open normal Chrome browser on the left side
WebDriver normalChrome = openChromeBrowserPlain()

resizeHorizontalHalfLocateLeft(normalChrome)

DriverFactory.changeWebDriver(normalChrome)

WebUI.navigateToUrl('https://inscape-operations-staging.stratusolvecloud.com/App/Student/Workflow/NewEnrolment/2022')

WebUI.waitForPageLoad(10)

// open incognito Chrome browser on the right side
ChromeOptions options = new ChromeOptions()

options.addArguments('--incognito')

WebDriver incognitoChrome = new ChromeDriver(options)

resizeHorizontalHalfLocateRight(incognitoChrome)

DriverFactory.changeWebDriver(incognitoChrome)

WebUI.navigateToUrl('https://inscape-connect-staging.stratusolvecloud.com/UserManagement/login/')

WebUI.waitForPageLoad(10)

DriverFactory.changeWebDriver(normalChrome)

// Enters the First Name
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Welcome to INCONNECT - our online stu_0eecac'),
	firstName)

// Enters the Last Name
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Welcome to INCONNECT - our online stu_d2ddfb'),
	surname)

// Enters the Cell Phone Number: This is not validated, so it can always be the same
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_land Islands_cell'),
	'0790000000')

// Enters the Email Address: This is validated, it has to be unique
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Valid_c3'),
	email)

// Country of Origin Selection of South Africa
WebUI.selectOptionByValue(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/select_Country of OriginSouth AfricaUnited _72b9c5'),
	'1', false)

// ID Type Selection of Passport Number
WebUI.selectOptionByValue(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/select_--Select ID Type--RSA ID NumberPassp_e4a2f7'),
	'2', false)

// Enters the Passport Number: This is validated, it has to be unique
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Valid_c7'),
	passportNumber)

// Enters the Password
WebUI.setEncryptedText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Valid_c4'),
	'p4y+y39Ir5PEPmX20UxFKw==')

// Enters the Confirm Password
WebUI.setEncryptedText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_A digit (0-9) is required_c5'),
	'p4y+y39Ir5PEPmX20UxFKw==')

// Clicks the "Next" Button
WebUI.click(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/button_Next'))

// Sets the OTP from the Noted Feedback as a variable "OTP"
OTP = WebUI.getText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/span_6031'))

// On the modal, enters the OTP by pasting the OTP variable that it stored
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Please check your junk mail folder if_d47c1f'),
	OTP)

ChromeDriver openChromeBrowserPlain() {
	return openChromeBrowser(new ChromeOptions())
}

ChromeDriver openChromeBrowserInIncognitoMode() {
	ChromeOptions options = new ChromeOptions()

	options.addArguments('–-incognito')

	return openChromeBrowser(options)
}

ChromeDriver openChromeBrowser(ChromeOptions options) {
	System.setProperty('webdriver.chrome.driver', DriverFactory.getChromeDriverPath())

	return new ChromeDriver(options)
}

Dimension resizeHorizontalHalfLocateLeft(WebDriver driver) {
	Dimension d = resizeToHorizontalHalf(driver)

	driver.manage().window().setPosition(new Point(0, 0))

	return d
}

Dimension resizeHorizontalHalfLocateRight(WebDriver driver) {
	Dimension d = resizeToHorizontalHalf(driver)

	driver.manage().window().setPosition(new Point(d.getWidth(), 0))

	return d
}

Dimension resizeToHorizontalHalf(WebDriver driver) {
	driver.manage().window().maximize()

	Dimension maxDim = driver.manage().window().getSize()

	Dimension curDim = new Dimension(((maxDim.getWidth() / 2) as Integer), maxDim.getHeight())

	driver.manage().window().setSize(curDim)

	return curDim
}

Screenshots:

// Clicks the "Next" Button 
WebUI.click(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/button_Next')) 

// Sets the OTP from the Noted Feedback as a variable "OTP" 
OTP = WebUI.getText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/span_6031')) 

// On the modal, enters the OTP by pasting the OTP variable that it stored 
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Please check your junk mail folder if_d47c1f'), OTP)

My guess, the WebUI.click() causes the browser to get “busy” doing something. When you come to WebUI.setText() it’s not ready – that’s generally what causes “not interactable”. Try adding a delay or, better, WebUI.waitForElementVisible().

In general terms, it’s good policy to wait for everything, especially when you cause changes to the page state (like clicking “next”). If you get all your waits done first, then continue with your test steps, your code will be more robust.

1 Like

Thank you! With some playing around this works. Man thank you so much!

With all the help lately, I need to actually document it and make note. This is an amazing community. Please tell me if I am asking too many questions

2 Likes

Of course you’re asking too many questions – it’s slowing YOU down :upside_down_face:

But seriously, we don’t mind at all. The reason you’re getting such good results from us is down to the quality of your posts/questions. Most new users seem to think we’re standing right next to them looking over their shoulder – they must think we’re magicians or something. Your posts are laden with good info which helps us enormously.
:dart:

2 Likes