Bird
0
0

Why does cy.location('pathname') sometimes return an empty string in Cypress tests?

hard📝 Conceptual Q10 of 15
Cypress - Navigation and URL
Why does cy.location('pathname') sometimes return an empty string in Cypress tests?
ABecause cy.location() cannot read pathname
BBecause the URL is invalid
CBecause the page is loaded at the root URL with no path
DBecause the test did not wait for page load
Step-by-Step Solution
Solution:
  1. Step 1: Understand pathname meaning

    Pathname is the part after domain; if URL is root (e.g., https://example.com), pathname is empty string or '/'.
  2. Step 2: Rule out other causes

    cy.location() can read pathname, URL validity is unrelated, and waiting affects timing but not pathname value.
  3. Final Answer:

    Because the page is loaded at the root URL with no path -> Option C
  4. Quick Check:

    Root URL pathname can be empty string [OK]
Quick Trick: Root URL pathname may be empty string [OK]
Common Mistakes:
  • Assuming empty string means error
  • Blaming cy.location() for missing data
  • Ignoring URL structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes