regex - How to improve the Xpath using the regular expression -
i using seleniumwebdriver identify elements , in 1 of instance, have defined 1 of xpath mentione below.
//div[contains(@id,'confirm1_container') or contains (@id,'confirm2_container') or contains(@id,'confirm3_container') or contains (@id,'confirm4_container')or contains (@id,'permanentsuppressionpopup_container')] the reason this, should pass 1 of them , identify element.
the question here, there easy way or suggestion improve xpath instead of having multiple or operators.if see theid's change "number" in between confirm , _container.
i did go through old suggestion talk xpath 2.0 functions cannot used in case.
//div[contains(@id,'confirm1_container') or contains (@id,'confirm2_container') or contains(@id,'confirm3_container') or contains (@id,'confirm4_container')or contains (@id,'permanentsuppressionpopup_container')] since above mentioned xpath uses or expression, identify first element in list matches 1 of statements (given use .findelement()).
so, in case simplify using:
//div[contains(@id,'_container')] since ids contain _container part.
if have other elements on page end _container part, try this:
//div[contains(@id,'_container') , contains(@id,'confirm') or contains(@id,'permanentsuppressionpopup')] it's not shorter much, still it's easier manage.
Comments
Post a Comment