Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

I.grabTextFrom() fails when there is no text #4487

Unanswered
nvadiga asked this question in Q&A
Discussion options

I have a table with following structure and I want to get text inside "p" tag. Text can be empty. In such cases I.grabTextFrom() fails with ElementNotFound exception. I was expecting it to return "" (empty string). Even the try catch block won't catch this exception. Any workaround for this issue?

Sample HTML

<tr>
<td><p>Field1</p></td>
<td><p></p>sometext</td>
</tr>
<tr>
<td><p>Field2</p></td>
<td><p></p></td>
</tr>

Code to grabtext

 let element = { xpath: `//p[text()='${fieldName}']/following::p` };
 try {
 // I see element passes fine 
 I.seeElement(element);
 return await I.grabTextFrom(element);
 } catch (error) {
 return "";
 }

Error

Element "xpath=//p[text()='Field2']/following::p" was not found by text|CSS|XPath
 at new ElementNotFound (node_modules/codeceptjs/lib/helper/errors/ElementNotFound.js:15:11)
 at assertElementExists (node_modules/codeceptjs/lib/helper/Playwright.js:3742:11)
 at Playwright.grabTextFrom (node_modules/codeceptjs/lib/helper/Playwright.js:2089:5)

Codeceptjs: 3.6.5
Browser: chromium
Helper: Playwright

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /