Given xpath expression "" is invalid: SyntaxError

Hi,

I’m working with KS 5.5 because having a problem with xPath in KS 5.6 and higher. I have defined object by xPath: //div[contains(@style, ‘position: fixed; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 2147483647;’)] and after executing in KS occures:

9-11-2018 09:11:30 dop. - [FAILED] - Unable to wait for object ‘Object Repository/IB/Common/Loading’ to be present (Root cause: org.openqa.selenium.InvalidSelectorException: Given xpath expression “” is invalid: SyntaxError: The expression is not a legal expression.
For documentation on this error, please visit: Selenium
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘MCHALANEK-10’, ip: ‘10.200.173.43’, os.name: ‘Windows 10’, os.arch: ‘x86’, 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: 62.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 43760, moz:profile: C:\Users\mchalanek\AppData\…, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, proxy: Proxy(direct), rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 4f7be76a-aa06-417a-a449-aadf05d6e839
*** Element info: {Using=xpath, value=})
09-11-2018 09:11:30 dop. - [END] - End action : Statement - common.Combase.untilLoading()
09-11-2018 09:11:30 dop. - [FAILED] - Test Cases/IB/Common/Initialization FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Unable to wait for object ‘Object Repository/IB/Common/Loading’ to be present (Root cause: org.openqa.selenium.InvalidSelectorException: Given xpath expression “” is invalid: SyntaxError: The expression is not a legal expression.
For documentation on this error, please visit: Selenium

Please for help

Thanks

The XPath you typed

//div[contains(@style, 'position: fixed; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 2147483647;')]

looks valid.

But Katalon is saying Given xpath expression "" is invalid

I doubt, what you typed here may be different from what is running in Katalon.

Could you take screenshot that shows us how the ‘Object Repository/IB/Common/Loading’ is defined?

And screenshot of the target HTML is required.

I found a substitute solution

This method not working

but this method is OK

Tested in FF62.0/Chrome68.0

image.png

2018-09-11 10_02_25-Katalon Studio - JAT - [Location_ C__Bitbucket_JAT_automatic-tests].png

2018-09-11 10_04_24-Katalon Studio - JAT - [Location_ C__Bitbucket_JAT_automatic-tests].png

If you use the style attribute to identify a HTML node, then you should rather use CSS Selector than XPath. XPath is whitespace sensitive. I mean the following 2 XPaths are not identical

//div[contains(@style, 'position: fixed; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 2147483647;')]
//div[contains(@style, 'position:fixed;left:0px;right:0px;top:0px;bottom:0px;z-index:2147483647;')]

This strictness tends to cause trouble. CSS Selector is free from this ‘whitespece sensitiveness’

Thanks a lot kazurayam. xPath without whitespace working.