-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
@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
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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
`
Beta Was this translation helpful? Give feedback.
All reactions
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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']
Beta Was this translation helpful? Give feedback.
All reactions
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank You.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1