Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use xpath locator in Cypress with TypeScript project?

Initially, xpath plug-in was working good with my cypress project. Installed typescript plugin and Moved from javascript to Typescript. Now It started throwing an error on xpath

Property 'xpath' does not exist on type 'cy & EventEmitter'.ts(2339)

enter image description here

Please suggest , how to use xpath with typescript in Cypress project ? cypress-xpath": "^1.6.2", is included in package.json

package.json file is as below:

"devDependencies": {
    "@types/node": "^14.17.8",
    "add": "^2.0.6",
    "cypress-cucumber-preprocessor": "^4.3.0",
    "cypress-mochawesome-reporter": "^2.2.0",
    "cypress-xpath": "^1.6.2",
    "typescript": "^4.4.3",
    "yarn": "^1.22.10"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true
  }
like image 603
user3302083 Avatar asked Oct 17 '25 10:10

user3302083


1 Answers

For this to work you have to add this in your tsconfig.json file.

{
  "compilerOptions": {
    "types": ["cypress", "cypress-xpath"]
  }
}
like image 195
Alapan Das Avatar answered Oct 20 '25 11:10

Alapan Das



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!