Cypress click element by ID / XPATH / Name?

前端 未结 5 1868
一整个雨季
一整个雨季 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:52

    #hdtb-msb-vis is an ID-selector and .category is a class-selector. But you should be able to select purely by the class-selector

    cy.get('.category')
      .click()
    

    But if that class is not unique you can click it via the ID and then the class:

    cy.get('#hdtb-msb-vis')
      .find('.category')
      .click()
    

提交回复
热议问题