Cypress- automated testing - the issue of access elements encountered and solutions

1, input type tag can not be written as a number in the value of the element chrome browser

<Input type = number, id = 'hr' .......> when writing data to this element, a cy.get ( '# hr'). Type () manner, chrome browser the write fails, use electron browser to run can run successfully found a chrome browser bug.

Solution: Use setAttruibute method, changing the type of element, and then data is written.

Specific methods: cy.get ( '# hr') then ((e1) => {.

  el.setAttriubute('type','text')

}). Type ( 'value')

2, input data is written to the tag attribute readonly

<Input type = text, id = 'hr', readonly .......> when writing data to this element, the elements may be deleted before re-writing readonly

Solution: Use removeAttr () method of changing the type of element, and then data is written.

Specific methods:.. Cy.get ( '# hr') then ((e1) => {el.removeAttr ( 'readonly')}) type ( 'value')

3, how the case data is written occlusion interface element

Sometimes, we input data in the interface, for example, drop-down box just blocking write input box, there may not be Cypress element, a method using an input force {force: true}.

cy.get('#hr').type('值',{force:true}.)

This method can also be used when clicks, click ({force: true}).

Guess you like

Origin www.cnblogs.com/memebuguoshixingfu/p/11941770.html