Illegal xpath expression, can't spot the error any help appreciated...

65 views
Skip to first unread message

Jonn Doe

unread,
May 24, 2024, 5:02:59 AMMay 24
to Selenium Users

 File "/home/ej/.pyenv/versions/webnovel/lib/python3.12/site-packages/selenium/webdriver/support/wait.py", line 96, in until
    value = method(self._driver)
            ^^^^^^^^^^^^^^^^^^^^
  File "/home/ej/.pyenv/versions/webnovel/lib/python3.12/site-packages/selenium/webdriver/support/expected_conditions.py", line 84, in _predicate
    return driver.find_element(*locator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ej/.pyenv/versions/webnovel/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 741, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ej/.pyenv/versions/webnovel/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/home/ej/.pyenv/versions/webnovel/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)


selenium.common.exceptions.InvalidSelectorException: Message: Given xpath expression 

"//a[ends-with(text(),"Strongest Sword God")][1]" 

is invalid: SyntaxError: Document.evaluate: 
The expression is not a legal expression; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#invalid-selector-exception


Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5
InvalidSelectorError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:432:5
find_@chrome://remote/content/shared/DOM.sys.mjs:170:11

Grigoriy Frank

unread,
May 24, 2024, 5:48:07 AMMay 24
to seleniu...@googlegroups.com
Try locator: (//a[ends-with(text(),"Strongest Sword God")])[1]


пт, 24 мая 2024 г., 17:03 Jonn Doe <jonn.do...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/2c6356b3-9ac6-492d-8461-70d52920fcddn%40googlegroups.com.

Jonn Doe

unread,
May 24, 2024, 7:09:31 AMMay 24
to Selenium Users

Tried , not working, works on @href but the text() fails diff value obviously for the text() and @href.

Odd. Went back to use @href search.

Adrian

unread,
May 26, 2024, 5:10:42 PMMay 26
to Selenium Users
Hi,
The selector is failing because of the use of incorrect usage of double quotes.

"//a[ends-with(text(),"Strongest Sword God")][1]" 

The inner double quotes is causing confusion.  Try using single quotes for the text instead like:
"//a[ends-with(text(),'Strongest Sword God')][1]" 


Cheers,
Adrian.


fm.coder teacher

unread,
Jun 1, 2024, 12:21:50 AMJun 1
to seleniu...@googlegroups.com
"//a[ends-with(text(),"Strongest Sword God")][1]" 
recommendation is to use double quotes and single quotes like so " something ='zzz' " or 'something = "zzz" '
try using quotes properly

HTH

Reply all
Reply to author
Forward
0 new messages