The rundown:
I have a script that runs through a site checkout flow, and then compares the values for each line item/fee before the order is placed (order summary) and after the order is placed (order confirmation). I have six values that get grabbed by WebUI.getText(), all on the same page and mostly within the same table. Four of that six have no issue, but the text for “Subtotal” and “Order Total” are being read as “” (no value), but the rest of the values are read just fine. My initial thought was that the locator for those two values were not correct, but that didn’t work out.
This had been working flawlessly a few weeks ago, but then the developers took it back to make additional changes elsewhere, and there has been a few Chrome updates since then. I also tried running it on other browsers with the same result. Any ideas?
Right off the bat, no… but let’s see if we can move you forward.
You’re obviously comfortable in DevTools. Can you use CSS selectors directly comparable to you XPaths and prove to yourself that the elements work as expected in DevTools?
You’ll want to use lines like this in the DevTools console:
document.querySelector("your css selector for subtotal").innerText;
Had you given me a screenshot of your HTML, I might have been able to write a fully working querySelector for you
body > div.site-wrapper > div > div > div > div.order-status-app > div > div.order-status-wrapper.order-section > div > div:nth-child(2) > div > div:nth-child(3) > p:nth-child(2)
to find inner text did indeed return the $1.00 I was expecting.
nth-of-type(5) landed on the taxes field, but it’s easy enough to point in the right spot.
They’re all returning their visible values in DevTools console. Should I slot that code into my method somewhere or just replace the locator in the object?
This XPath expression selects a <p> element which is just next to <p>Subtotal</p> which is inside <div class="order-summary-section"> in the target HTML document.
This XPath expression selects a <p> element which is just next to <p>Subtotal</p>which is inside <div class="order-summary-section"> in the target HTML document. However here I assume that there is only one <p>Subtotal</p> in the document.
If you want to learn more about XPath following-sibling axes, read this artile.
These expressions do not depend on the relative position of the parent node <div class="line-item"></div>. The relative position (5) of the parent node tends to change when the Web page is redesigned. These expressions rather use the text Subtotal as the key to identify the data item you want ($1.00).
A human-visible text (such as Subtotal) in a Web page tends to be sustained/unchanged when the Web page is redesigned. So the above expression could be a bit more robust against the HTML change.