@@ -76,6 +76,7 @@ def _filter_xpath_grouping(xpath):
76
76
77
77
def _get_raw_css_from_xpath (xpath ):
78
78
css = ""
79
+ attr = ""
79
80
position = 0
80
81
81
82
while position < len (xpath ):
@@ -108,7 +109,9 @@ def _get_raw_css_from_xpath(xpath):
108
109
attr = '[%s*="%s"]' % (match ['cattr' ].replace ("@" , "" ),
109
110
match ['cvalue' ])
110
111
elif match ['cattr' ] == "text()" :
111
- attr = ":contains(%s)" % match ['cvalue' ]
112
+ attr = ':contains("%s")' % match ['cvalue' ]
113
+ elif match ['cattr' ] == "." :
114
+ attr = ':contains("%s")' % match ['cvalue' ]
112
115
else :
113
116
attr = ""
114
117
@@ -128,6 +131,20 @@ def _get_raw_css_from_xpath(xpath):
128
131
def convert_xpath_to_css (xpath ):
129
132
if xpath [0 ] != '"' and xpath [- 1 ] != '"' and xpath .count ('"' ) % 2 == 0 :
130
133
xpath = _handle_brackets_in_strings (xpath )
134
+ xpath = xpath .replace ("descendant-or-self::*/" , "descORself/" )
135
+ xpath = xpath .replace (" = '" , "='" )
136
+ if " and contains(@" in xpath and xpath .count (" and contains(@" ) == 1 :
137
+ spot1 = xpath .find (" and contains(@" )
138
+ spot1 = spot1 + len (" and contains(@" )
139
+ spot2 = xpath .find ("," , spot1 )
140
+ attr = xpath [spot1 :spot2 ]
141
+ swap = " and contains(@%s, " % attr
142
+ if swap in xpath :
143
+ swap_spot = xpath .find (swap )
144
+ close_paren = xpath .find (']' , swap_spot ) - 1
145
+ if close_paren > 1 :
146
+ xpath = xpath [:close_paren ] + xpath [close_paren + 1 :]
147
+ xpath = xpath .replace (swap , "_STAR_=" )
131
148
132
149
if xpath .startswith ('(' ):
133
150
xpath = _filter_xpath_grouping (xpath )
@@ -149,4 +166,16 @@ def convert_xpath_to_css(xpath):
149
166
css = css .replace ('_STR_L_bracket_' , '\\ [' )
150
167
css = css .replace ('_STR_R_bracket_' , '\\ ]' )
151
168
169
+ # Handle a lot of edge cases with conversion
170
+ css = css .replace (" > descORself > " , ' ' )
171
+ css = css .replace (" descORself > " , ' ' )
172
+ css = css .replace ("/descORself/*" , ' ' )
173
+ css = css .replace ("/descORself/" , ' ' )
174
+ css = css .replace ("descORself/" , ' ' )
175
+ css = css .replace ("_STAR_=" , "*=" )
176
+ css = css .replace ("]/" , "] " )
177
+ css = css .replace ("] *[" , "] > [" )
178
+ css = css .replace ("\' " , '"' )
179
+ css = css .replace ("[@" , '[' )
180
+
152
181
return css
0 commit comments