Search code examples
seleniumxpathwebdriver

xpath find by part of class value


I wanna know is it possible to find element using xpath for part of class name value? I mean sometimes one element have many classes like below:

<p class="SnippetBodyStyles__MainInfo-sc-1asbgpf-4 fBmSdW">bla bla bla</p>

and i want to find element by one of this class.

So tag p relate to two classes:

  1. SnippetBodyStyles__MainInfo-sc-1asbgpf-4
  2. fBmSdW

Is it possible to find p tag using this xpath like text contains:

p[@class[text(),[contains(,"fBmSdW")]]]

?


Solution

  • Yes, try the below xpath expression

    //p[contains(@class,"fBmSdW")]