1

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")]]]

?

555Russich
  • 354
  • 2
  • 10

2 Answers2

3

Yes, try the below xpath expression

//p[contains(@class,"fBmSdW")]
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Md. Fazlul Hoque
  • 15,806
  • 5
  • 12
  • 32
0

See in this line of code you can make many types of Xpath but in my opinion, it is better to use Xpath with single attribute or Xpath with TextAttribute. If you want, there are many other types you can use. Xpath with single attribute-//p[@class='SnippetBodyStyles__MainInfo-sc-1asbgpf-4 fBmSdW'] Xpath with TextAttribute-//p[text()='bla bla bla'] Make sure that your Xpath will be unique for that go to your project >> Inspect >> Ctrl F >> In that search bar paste your Xpath If is showing 1 of 1 then that Xpath is unique & you can use it. enter image description here