如何使用cssselector将css转换为xpath

时间:2017-04-23 16:32:49

标签: python-3.x selenium-webdriver css-selectors

我想使用一些库将css选择器转换为xpath。任何人都可以向我解释返回值的含义以及我如何覆盖xpath,如//div//*[class@""]

from cssselect import GenericTranslator

try
    sel = CSSSelector('div.w3-container.top')
except SelectorError:
    print('Invalid selector.')
print(sel)

sel:
'descendant-or-self::div[@class and contains(concat(\\' \\', normalize-space(@class), \\' \\'), \\' w3-container \\') and (@class and contains(concat(\\' \\', normalize-space(@class), \\' \\'), \\' top \\'))]'

1 个答案:

答案 0 :(得分:1)

XPath(GenericTranslator().css_to_xpath('div.w3-container.top'))

这将返回给定css类的XPath

访问此link了解详情