Cypress click element by ID / XPATH / Name?

前端 未结 5 1850
一整个雨季
一整个雨季 2021-02-20 11:40

I want to click on an element by XPATH / ID and not the default cypress locator, is it possible?

In selenium I can use find element by XPATH for example:



        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 11:54

    There are 2 things to be done if trying to use xpath in cypress:-

    1. In the file 'index.js' which sits under the folder 'YourProject'->'cypress'->'support', add the entry "require('cypress-xpath')"
    2. In the file 'Dockerfile.cypress' which sits under the folder 'YourProject'->'configuration'->'docker', add the entry "RUN npm install cypress-xpath"

    That's all you need to use all the xpath functions to uniquely identify all elements in your cypress tests. I personally prefer using xpath since this gives me more control on the UI elements. Hope this will make life more easier in using cypress.

提交回复
热议问题