0

I am using playwright with c# .net. When I tried to click on element using getByRole or xpath, It is working fine. When I tried using getByText or getByTitle neither it is giving error nor it is clicking on it. Please see attached image. I want to click on "Sales". enter image description here

I tried following syntax:

await page.GetByText("Sales", new() { Exact = true }).ClickAsync();
await page.GetByText("Sales").ClickAsync();

Can someone tell me, how to use getByText?

JIST
  • 1,139
  • 2
  • 8
  • 30

1 Answers1

0

Here is getByText detailed usage example:

Consider the following DOM structure:

<div>Hello <span>world</span></div>
<div>Hello</div>

You can locate by text substring, exact string, or a regular expression:

   // Matches <span>
page.getByText("world")

// Matches first <div>
page.getByText("Hello world")

// Matches second <div>
page.getByText("Hello", new Page.GetByTextOptions().setExact(true))

// Matches both <div>s
page.getByText(Pattern.compile("Hello"))

// Matches second <div>
page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23