1

I am trying to grab just the order number in the h1

<h1 class="FulfillmentHeaderstyles__FulfillmentHeaderTitle-sc-1ges29w-3 PjsJX">
   Order #1004066
   <div aria-label="promise time" class="FulfillmentHeaderstyles__FulfillmentPromiseTime-sc-1ges29w-7 elUWJn">7:09 PM</div>
</h1>

Code tried

const orderNumber = await window.locator('[class*=FulfillmentHeaderTitle]').textContent();
console.log(orderNumber);

Console log result: Order #10040657:09 PM

How can I grab just the order number "Order #1004065" and not the child. Thanks in advance!

Sundar
  • 11
  • 3
  • Since the textContent keeps new lines, you could split the string on that? `orderNumber.split('\n').at(1) // " Order #1004066"` – evolutionxbox Feb 02 '23 at 00:48

1 Answers1

0

You could do something like this:

console.log(document.querySelector('h1').innerText.split('\n')[0])
<h1 class="FulfillmentHeaderstyles__FulfillmentHeaderTitle-sc-1ges29w-3 PjsJX">
   Order #1004066
   <div aria-label="promise time" class="FulfillmentHeaderstyles__FulfillmentPromiseTime-sc-1ges29w-7 elUWJn">7:09 PM</div>
</h1>

Here you get the innerText and then split it at the line break to get an array, which looks like ['Order #1004066', '7:09 PM']. So, you take the first element at index 0 to get the order number.

Geshode
  • 3,600
  • 6
  • 18
  • 32