selenium simple test says xpath is not a legal expression
It's not a valid XPath expression. This
//div[div@data-type="folder-name"]
Should probably read
//div[div/@data-type="folder-name"]
which is indeed what you have in one of your examples.
bmacnaughton
I cut my teeth on kernel-mode systems software, C, assembler, and Bliss, among other languages. I designed and led the implementation of H&R Block's Rapid Refund - large scale, highly distributed, high-throughput enterprise software. Now I prefer to spend my time working with Rust, JavaScript, Python, and the libraries extending them. I have the uncommon mix of understanding low-level fundamentals and high-level architectures. I like to understand how the pieces work so I know how to best use them. Recent work, in reverse order, includes Rust security software, Node.js security and application performance monitoring software, Node.js addons in C/C++, a Vue.js front-end and PHP backend for https://lemajordome.ch/, a viral adoption simulator using Python, a framework for paper.js graphic designs, and an API using JQuery and AngularJS that communicates with a backend Internet of Things server.
Updated on June 04, 2022Comments
-
bmacnaughton almost 2 years
I started using SST (selenium simple test) but ran into a problem when executing what seems to be a valid xpath expression
'//div[div@data-type="folder-name"]'
. SST fails with the following traceback:Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/sst/cases.py", line 207, in run_test_script exec self.code in self.context File "./sst-one.py", line 7, in <module> names = get_elements_by_xpath('//div[div@data-type="folder-name"]') File "/usr/local/lib/python2.7/dist-packages/sst/actions.py", line 1344, in >get_elements_by_xpath_raise(msg) File "/usr/local/lib/python2.7/dist-packages/sst/actions.py", line 118, in _raise raise AssertionError(msg) AssertionError: Element not found: Message: u'The given selector //div[div@data->type="folder-name"] is either invalid or does not result in a WebElement. The following >error occurred:\nInvalidSelectorError: Unable to locate an element with the xpath >expression //div[div@data-type="folder-name"] because of the following >error:\n[Exception... "The expression is not a legal expression." code: "12" nsresult: >"0x805b0033 (SyntaxError)" location: "file:///tmp/tmp12zCta/extensions/[email protected]/components/driver_component.js> Line: 5916"]' ; Stacktrace: at FirefoxDriver.annotateInvalidSelectorError_ (file:///tmp/tmp12zCta/extensions/[email protected]/components/driver_component.js:8873) at FirefoxDriver.prototype.findElementsInternal_ (file:///tmp/tmp12zCta/extensions/[email protected]/components/driver_component.js:8931) at FirefoxDriver.prototype.findElements file:///tmp/tmp12zCta/extensions/[email protected]/components/driver_component.js:8935) at DelayedCommand.prototype.executeInternal_/h file:///tmp/tmp12zCta/extensions/[email protected]/components/command_processor.js:10840) at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp12zCta/extensions/[email protected]/components/command_processor.js:10845) at DelayedCommand.prototype.execute/< file:///tmp/tmp12zCta/extensions/[email protected]/components/command_processor.js:10787)
The SST code line is:
names = get_elements_by_xpath('//div[div@data-type="folder-name"]')
If I run the same xpath statement using selenium (from python), not SST, it is a valid expression and returns the matching elements if there were any.
The pure selenium code line (where br is the firefox webdriver object) is:
elems = br.find_elements_by_xpath("//div[div/@data-type='folder-name']")
I understand this is a bit in the weeds, so if anyone has some hints as to how to debug the .js code that selenium creates in the /tmp directory that would be a big help.