Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Getting an error message when using a long xpath #1098

Answered by mdmintz
maburrub asked this question in Q&A
Discussion options

I am getting this error:
Invalid or unsupported Xpath: //div[contains(@Class,'deals_index_deal-board_column')][./descORself/camp-text[text()='To Contact']]/descORself/camp-text[text()='deal16384118080']

in Ghrome dev tools, this xpath is valid and can select the desired element but seleniumbase is not happy about it.

You must be logged in to vote

@maburrub /descORself/ is not a real xpath component. It's a temporary replacement of descendant-or-self::*/ (https://developer.mozilla.org/en-US/docs/Web/XPath/Axes/descendant-or-self) for specific use in converting an xpath selector into a css selector for cases where pure javascript or jquery was necessary instead of regular selenium methods. That /descORself/ should only exist within xpath-to-css conversion, and should not be found in the wild. You can avoid such problems by using CSS Selectors whenever possible.

Replies: 5 comments 1 reply

Comment options

@maburrub That's definitely not valid XPath. Can you show me the original line of code that generated the error? It looks like a selector that was in the middle of being converted into CSS from XPath, but it didn't quite get there.

You must be logged in to vote
1 reply
Comment options

Can you please tell me what is wrong with the xpath? I have not compsed it myself I am just using it however it chrome dev tools it works ok, it can identify the objects I am interested in. Here is an error dump.

`[undefined]seleniumbase.fixtures.xpath_to_css.XpathException: Invalid or unsupported Xpath: //div[contains(@Class,'d_i_d_b_c')][./descORself/camp-text[text()='To Contact']]/descORself/camp-text[text()='dl16']

venv/lib/python3.9/site-packages/seleniumbase/fixtures/base_case.py:2024: in drag_and_drop
drag_selector = self.convert_to_css_selector(drag_selector, drag_by)
venv/lib/python3.9/site-packages/seleniumbase/fixtures/base_case.py:5387: in convert_to_css_selector
return self.convert_xpath_to_css(selector)
venv/lib/python3.9/site-packages/seleniumbase/fixtures/base_case.py:5369: in convert_xpath_to_css
return xpath_to_css.convert_xpath_to_css(xpath)
venv/lib/python3.9/site-packages/seleniumbase/fixtures/xpath_to_css.py:209: in convert_xpath_to_css
css = _get_raw_css_from_xpath(xpath)


xpath = "//div[contains(@Class,'d_i_d_b_c')][./descORself/camp-text[text()='To Contact']]/descORself/camp-text[text()='dl16']"

def _get_raw_css_from_xpath(xpath):
 css = ""
 attr = ""
 position = 0
 while position < len(xpath):
 node = prog.match(xpath[position:])
 if node is None:
 raise XpathException("Invalid or unsupported Xpath: %s" % xpath)

E seleniumbase.fixtures.xpath_to_css.XpathException: Invalid or unsupported Xpath: //div[contains(@Class,'d_i_d_b_c')][./descORself/camp-text[text()='To Contact']]/descORself/camp-text[text()='dl16']

venv/lib/python3.9/site-packages/seleniumbase/fixtures/xpath_to_css.py:87: XpathException
`

Comment options

@maburrub /descORself/ is not a real xpath component. It's a temporary replacement of descendant-or-self::*/ (https://developer.mozilla.org/en-US/docs/Web/XPath/Axes/descendant-or-self) for specific use in converting an xpath selector into a css selector for cases where pure javascript or jquery was necessary instead of regular selenium methods. That /descORself/ should only exist within xpath-to-css conversion, and should not be found in the wild. You can avoid such problems by using CSS Selectors whenever possible.

You must be logged in to vote
0 replies
Answer selected by mdmintz
Comment options

I am sorry I did not pay attention to the difference between the original xpath and the error message. Here is the original xpath and the error message so back to my quesiton is it an invalid xpath to begin with ? or not. let me know what you think:

"//div[contains(@Class,'deals_index_deal-board_column')][.//camp-text[text()='To Contact']]//camp-text[text()='deal16384687810']"

[undefined]seleniumbase.fixtures.xpath_to_css.XpathException:
Invalid or unsupported Xpath:

//div[contains(@Class,'deals_index_deal-board_column')][./descORself/camp-text[text()='To Contact']]/descORself/camp-text[text()='deal16384687810']

You must be logged in to vote
0 replies
Comment options

@maburrub That's a very complex xpath. There are brackets inside of brackets, eg: [.//camp-text[text()='To Contact']]. And it looks like it might have contradictory data (camp-text is set twice with two different values.) Whether it's technically valid or not (I'm leaning toward not) it's definitely not the best selector for the element you're looking for.
Maybe a smaller selector such as 'camp-text:contains("deal16384687810")' is what you're really looking for.

You must be logged in to vote
0 replies
Comment options

Thank You.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /