Sara
Sara

Reputation: 191

Playwright: Trying to Get text from label but it returns Strange locator

Look at the attached picenter image description here

Here is the inspect element enter image description here I am trying to fetch the WO No. When I click on WO No, I get following and I store it in WONo

  const WONo = page.getByLabel('WO No')

When I print it I get following, While to my understanding it should return 12204 as showin in the pink the pink area. Am, I understanding the whole thing incorrectly?

  Locator@internal:label="WO No"i

Any Hint/help will be appreciated. I am using typescript with plauwright. BR

Upvotes: 1

Views: 2298

Answers (3)

Akshay Pathak
Akshay Pathak

Reputation: 1

Try using this extension for getting the playwright path from the browser. https://chromewebstore.google.com/detail/letxpath/bekehlnepmijedippfibbmbglglbmlgk

Upvotes: 0

unickq
unickq

Reputation: 3408

Try to use innerText(), textContent(), inputValue().

Or the same functions for page.getByLabel('WO No').locator("input"), if innerText doesn't work

Upvotes: 1

Kiran Parajuli
Kiran Parajuli

Reputation: 1045

The return type of get_by_label is locator so you may need to do nested findings, get the input, and then read its value.

const WONo = await page.get_by_label('WO No')

const WONo_value = await WONo.get_by_role('textbox').input_value()

Upvotes: 1

Related Questions