I am creating relatively complex xpath expressions in Python to pass them to selenium. However, it's pretty easy to make a mistake, so I'm looking for a library that allows me to create expressions without interfering with strings. For example, instead of writing
locator='//ul[@class="comment-contents"][contains(., "West")]/li[contains(., "reply")]
I could write something like:
import xpathbuilder as xpb locator = xpb.root("ul") .filter(attr="class",value="comment-contents") .filter(xpb.contains(".", "West") .subclause("li") .filter(xpb.contains (".", "reply"))
which may not be readable, but less error prone. Is there anything similar?
source share