Rayrun
← Back to Discord Forum

Locator.InnerText() returns material icon description

Hi. I use the Locator("myLocator").InnerTextAsync() function to fetch the div inner text but that div has also a button with no text but a material icon, which is represented by a text into the DOM. Should Playwright returns also that material icon description?

<div class="flex-fill overflow-hidden text-truncate"> <button type="button" class="btn btn-link link-dark p-0 border-0"> <span class="align-text-bottom material-icons material-icons-outlined md-18">more_vert</span> </button> "Number" </div>

This thread is trying to answer question "Should the Locator('myLocator').InnerTextAsync() function in Playwright return the material icon description along with the div inner text?"

5 replies
letsscrapedata
letsscrapedata

yes, if you only want to get "Number", try:

letsscrapedata
letsscrapedata

await frame.evaluate(ele => { let child = ele.firstChild; let texts = [];

while (child) {
      if (child.nodeType == 3) {
        texts.push(child.data);
      }
      child = child.nextSibling;
    }

    return texts.join(" ");
  }, $ele)
letsscrapedata
letsscrapedata

if needed, please send me the url, so I can check it with:

letsscrapedata
letsscrapedata

<column_element colname="c01" nickname="nickName"> <element loc="myLocator" /> <elecontent_text top="true" /> </column_element>

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.