Skip to content

Commit cbdc7b3

Browse files
committed
Add css_to_xpath.py
1 parent ea28ff2 commit cbdc7b3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

seleniumbase/fixtures/css_to_xpath.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Convert CSS selectors into XPath selectors
3+
"""
4+
5+
from cssselect import GenericTranslator
6+
7+
8+
def convert_css_to_xpath(css):
9+
""" Convert CSS Selectors to XPath Selectors.
10+
Example:
11+
convert_css_to_xpath('button:contains("Next")')
12+
Output => "//button[contains(., 'Next')]"
13+
"""
14+
xpath = GenericTranslator().css_to_xpath(css, prefix='//')
15+
return xpath

0 commit comments

Comments
 (0)