Unable to find the element located by 'By.xpath;

Hi all,

I need help. I cannot select the text entry box which has the Seleted Locator Xpath //input[@id=‘PanelSubmitJobStream_1_StringJobStream_value_1000984847’]

The last 10 digits of the id is a changing value and is unique every execution. I would like to have a wildcard to replace the 10 digits.
I’ve tried:
//[starts-with(@id,’PanelSubmitJobStream_1_StringJobStream_value’)]
//input[starts-with(@id,’PanelSubmitJobStream_1_StringJobStream_value’)]
//input[@id='PanelSubmitJobStream_1_StringJobStream_value_
']
Nothing worked.


Full console log:
2021-03-09 15:09:18.293 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2021-03-09 15:09:18.296 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/ENV01 Catchup A
2021-03-09 15:09:19.326 DEBUG testcase.ENV01 Catchup A - 1: openBrowser(“”)
2021-03-09 15:09:19.574 INFO c.k.k.core.webui.driver.DriverFactory - Starting ‘Firefox’ driver
Mar 09, 2021 3:09:19 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using new FirefoxOptions() is preferred to DesiredCapabilities.firefox()
2021-03-09 15:09:19.666 INFO c.k.k.core.webui.driver.DriverFactory - Action delay is set to 0 milliseconds
1615331361346 mozrunner::runner INFO Running command: “C:\Program Files\Mozilla Firefox\firefox.exe” “-marionette” “-foreground” “-no-remote” “-profile” “C:\Users\knguyen2\AppData\Local\Temp\2\rust_mozprofile.Fkh3dp6NhnFJ”
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can’t find profile directory.
1615331364535 Marionette INFO Listening on port 63156
1615331364966 Marionette WARN TLS certificate errors will be ignored for this session
1615331364966 Marionette INFO Proxy settings initialised: {“proxyType”:“direct”}
Mar 09, 2021 3:09:25 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
2021-03-09 15:09:25.059 INFO c.k.k.core.webui.driver.DriverFactory - sessionId = a7224bc2-5e22-44e9-9eae-bc9400344c53
2021-03-09 15:09:25.087 INFO c.k.k.core.webui.driver.DriverFactory - browser = Firefox 78.0
2021-03-09 15:09:25.087 INFO c.k.k.core.webui.driver.DriverFactory - platform = Windows 10
2021-03-09 15:09:25.088 INFO c.k.k.core.webui.driver.DriverFactory - seleniumVersion = 3.141.59
2021-03-09 15:09:25.088 INFO c.k.k.core.webui.driver.DriverFactory - proxyInformation = ProxyInformation { proxyOption=NO_PROXY, proxyServerType=HTTP, username=, password=********, proxyServerAddress=, proxyServerPort=0, executionList=“”, isApplyToDesiredCapabilities=true }
[FINE] No subscribers registered for event class com.kms.katalon.core.event.TestingEvent
[FINE] No subscribers registered for event class org.greenrobot.eventbus.NoSubscriberEvent
2021-03-09 15:09:25.110 DEBUG testcase.ENV01 Catchup A - 2: navigateToUrl(“https://lgtimoiws1.calpers.ca.gov:16311/ibm/console/logon.jsp”)
2021-03-09 15:09:26.830 ERROR c.k.k.c.w.d.KatalonSmartEventListener - :x: Unable to locate element: #katalon_only_element
For documentation on this error, please visit: Exceptions | Selenium
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘ESDD-58473’, ip: ‘10.26.151.75’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.core.webui.driver.firefox.CGeckoDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 78.1.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20200722151235, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 16116, moz:profile: C:\Users\knguyen2\AppData\L…, moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, proxy: Proxy(direct), rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: a7224bc2-5e22-44e9-9eae-bc9400344c53
*** Element info: {Using=id, value=katalon_only_element}
2021-03-09 15:09:26.832 DEBUG testcase.ENV01 Catchup A - 3: setText(findTestObject(“ENV01 Catchup A/Page_MO Workload Scheduler/input_User ID_j_username”), “knguyen2”)
2021-03-09 15:09:27.422 DEBUG testcase.ENV01 Catchup A - 4: setEncryptedText(findTestObject(“ENV01 Catchup A/Page_MO Workload Scheduler/input_Password_j_password”), “UouB6tyMF9wvngJ2hGQuhg==”)
2021-03-09 15:09:27.842 DEBUG testcase.ENV01 Catchup A - 5: click(findTestObject(“ENV01 Catchup A/Page_MO Workload Scheduler/input_Processing…_action”))
console.error: Policies.jsm:
Unable to add search engine
Message: [Exception… “An engine with that name already exists!” nsresult: “0x80520008 (NS_ERROR_FILE_ALREADY_EXISTS)” location: “JS frame :: resource://gre/modules/SearchUtils.jsm :: fail :: line 126” data: no]
Stack:
fail@resource://gre/modules/SearchUtils.jsm:126:22
addEngineWithDetails@resource://gre/modules/SearchService.jsm:2437:21
onAllWindowsRestored/</<@resource:///modules/policies/Policies.jsm:1660:41
runOncePerModification@resource:///modules/policies/Policies.jsm:2056:10
onAllWindowsRestored/<@resource:///modules/policies/Policies.jsm:1643:17

2021-03-09 15:09:29.274 DEBUG testcase.ENV01 Catchup A - 6: click(findTestObject(“ENV01 Catchup A/Page_MO Workload Scheduler/span_Submit Predefined Job Streams”))
JavaScript error: https://lgtimoiws1.calpers.ca.gov:16311/ibm/console/contentRender.do?oid=_1560750906&pageid=com.ibm.tws.WebUI.JobStreams.navigation;com.ibm.tws.WebUI;1615331368319&XSS=30d2a7520c6751f176f575a546e4021d, line 295: TypeError: document.getElementById(…) is null
2021-03-09 15:09:59.738 DEBUG testcase.ENV01 Catchup A - 7: setText(findTestObject(“ENV01 Catchup A/Page_MO Workload Scheduler/input_Job Stream_PanelSubmitJobStream_1_StringJobStream_value_1000984847”), “a01bnf7027*”)
SourceActor threw an exception: [Exception… “Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIInputStream.available]” nsresult: “0x80470002 (NS_BASE_STREAM_CLOSED)” location: “JS frame :: resource://devtools/shared/DevToolsUtils.js :: onResponse :: line 558” data: no]
Stack: onResponse@resource://devtools/shared/DevToolsUtils.js:558:34
onStopRequest@resource://gre/modules/NetUtil.jsm:128:18
Line: 558, column: 0
JavaScript error: resource://devtools/shared/DevToolsUtils.js, line 558: NS_BASE_STREAM_CLOSED: Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIInputStream.available]
2021-03-09 15:10:48.449 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by ‘By.xpath: //input[@id=‘PanelSubmitJobStream_1_StringJobStream_value_1000984847’]’. Please recheck the objects properties to make sure the desired element is located.
2021-03-09 15:10:48.620 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to set text ‘a01bnf7027*’ of object ‘Object Repository/ENV01 Catchup A/Page_MO Workload Scheduler/input_Job Stream_PanelSubmitJobStream_1_StringJobStream_value_1000984847’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to set text ‘a01bnf7027*’ of object ‘Object Repository/ENV01 Catchup A/Page_MO Workload Scheduler/input_Job Stream_PanelSubmitJobStream_1_StringJobStream_value_1000984847’
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.SetTextKeyword.setText(SetTextKeyword.groovy:66)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword.execute(SetTextKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.setText(WebUiBuiltInKeywords.groovy:977)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$setText$1.call(Unknown Source)
at ENV01 Catchup A.run(ENV01 Catchup A:32)
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:393)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:384)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:363)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:355)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:251)
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 TempTestCase1615331355755.run(TempTestCase1615331355755.groovy:25)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/ENV01 Catchup A/Page_MO Workload Scheduler/input_Job Stream_PanelSubmitJobStream_1_StringJobStream_value_1000984847’ located by ‘//input[@id=‘PanelSubmitJobStream_1_StringJobStream_value_1000984847’]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1369)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword$_setText_closure1.doCall(SetTextKeyword.groovy:51)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword$_setText_closure1.call(SetTextKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword.setText(SetTextKeyword.groovy:66)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword.execute(SetTextKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.setText(WebUiBuiltInKeywords.groovy:977)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$setText$1.call(Unknown Source)
at Script1612479434180.run(Script1612479434180.groovy:32)
… 11 more
)
2021-03-09 15:10:48.623 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/ENV01 Catchup A FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to set text ‘a01bnf7027*’ of object ‘Object Repository/ENV01 Catchup A/Page_MO Workload Scheduler/input_Job Stream_PanelSubmitJobStream_1_StringJobStream_value_1000984847’
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.SetTextKeyword.setText(SetTextKeyword.groovy:66)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword.execute(SetTextKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.setText(WebUiBuiltInKeywords.groovy:977)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$setText$1.call(Unknown Source)
at ENV01 Catchup A.run(ENV01 Catchup A:32)
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:393)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:384)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:363)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:355)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:251)
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 TempTestCase1615331355755.run(TempTestCase1615331355755.groovy:25)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/ENV01 Catchup A/Page_MO Workload Scheduler/input_Job Stream_PanelSubmitJobStream_1_StringJobStream_value_1000984847’ located by ‘//input[@id=‘PanelSubmitJobStream_1_StringJobStream_value_1000984847’]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1369)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword$_setText_closure1.doCall(SetTextKeyword.groovy:51)
at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword$_setText_closure1.call(SetTextKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 17 more

2021-03-09 15:10:48.633 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/ENV01 Catchup A

1 Like

I don’t use XPath but this CSS selector should work:

input[id^=PanelSubmitJobStream_1_StringJobStream_value]

This XPath should be fine. But you mentioned that you haved tried it and failed.

If it is true, the locator is not the reason of failure.

For example, you tried WebUI.setText() keyword and failed. So you can try “WebUI.sendKeys()” instead.

There could be many more difficult cases, but unable to see without getting in touch with the live system.

Root cause (at least in the provided stack trace) is indeed the locator. It looks like you are still passing in the number at the end. Try this one instead:

//input[contains(@id, 'PanelSubmitJobStream_1_StringJobStream_value_')]

You can (and should) also test this in the browser console ahead of time, before placing it in the Test Object.

I tried both solutions suggested above (CSS and WebUI.sendKeys) but didn’t work.

I have recorded from scratch and I have more details.

The XPath has a Parent iframe //input[starts-with(@id=‘PanelSubmitJobStream_1_StringJobStream_value’)]
image

I opened up the Parent iframe and updated to “ends-with” due to the unique changing digits in front each time.

Still failed.
=============== ROOT CAUSE =====================
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/New test/Page_MO Workload Scheduler/iframe_SubmitJobStreamintoPlan_isc_iframe’ located by ‘//iframe[ends-with(@id=‘iframe’)]’ not found

Click here to fix broken Test Object

03-10-2021 12:08:07 PM Test Cases/New Test Case

Elapsed time: 1m - 43.222s

Test Cases/New Test Case FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to set text ‘a01bnf7027*’ of object ‘Object Repository/New test/Page_MO Workload Scheduler/input_Job Stream_PanelSubmitJobStream_1_StringJobStream_value_381942929’

If the Test Object that contains your identifier for the field has a “Parent iframe” configured, I would recommend removing that (select the “No” radio option), and instead do the following:

1.) Create a separate Test Object for the iframe(s) involved, and use the WebUI.switchToFrame() keyword to switch to the appropriate context. If it’s a nested iframe (i.e. an iframe within an iframe), you’ll need to perform this step multiple times.

2.) After you are in the appropriate iframe (context), then try your WebUI.setText() call.

1 Like

You have this:

//iframe[ends-with(@id,'iframe')]

Unfortunately no browser supports the XPath 2.0 function ends-with(). It would never work.

You can write an alternative expression using XPath 1.0 functions substring and string-length:

//iframe[substring(@id, string-length(@id) - string-length('iframe') +1) = 'iframe']

I was having the same exact problem and the @Brandon_Hein post is the solution. After selecting the “no” radio option and using WebUI.switchToFrame() to the parent frame I was able to get the dynamic id elements. Im using findWebElements too. Thank you.

1 Like