
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
@cypress/xpath
Advanced tools
Adds XPath command to Cypress.io test runner
npm install -D @cypress/xpath
yarn add @cypress/xpath --dev
Then include in your project's support file
require('@cypress/xpath');
After installation your cy
object will have xpath
command.
it('finds list items', () => {
cy.xpath('//ul[@class="todo-list"]//li').should('have.length', 3);
});
You can also chain xpath
off of another command.
it('finds list items', () => {
cy.xpath('//ul[@class="todo-list"]').xpath('./li').should('have.length', 3);
});
As with other cy commands, it is scoped by cy.within()
.
it('finds list items', () => {
cy.xpath('//ul[@class="todo-list"]').within(() => {
cy.xpath('./li').should('have.length', 3);
});
});
note: you can test XPath expressions from DevTools console using $x(...)
function, for example $x('//div')
to find all divs.
In XPath the expression // means something very specific, and it might not be what you think. Contrary to common belief, // means "anywhere in the document" not "anywhere in the current context". As an example:
cy.xpath('//body').xpath('//script');
You might expect this to find all script tags in the body, but actually, it finds all script tags in the entire document, not only those in the body! What you're looking for is the .// expression which means "any descendant of the current node":
cy.xpath('//body').xpath('.//script');
The same thing goes for within:
cy.xpath('//body').within(() => {
cy.xpath('.//script');
});
For more, see Intelligent Code Completion
This project is licensed under the terms of the MIT license.
FAQs
Adds XPath command to Cypress.io test runner
The npm package @cypress/xpath receives a total of 40,705 weekly downloads. As such, @cypress/xpath popularity was classified as popular.
We found that @cypress/xpath demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.