• Cypress-自动化测试-获取元素过程中遇到的问题及解决方法


    1、input标签类型为number在chrome浏览器中无法写入元素的值

    <input type=number,id='hr'.......>向这个元素中写入数据的时候,使用cy.get('#hr').type()的方式,在chrome浏览器下写入失败,使用electron浏览器运行可以运行成功,发现是chrome浏览器的bug。

    解决方法:使用setAttruibute方法,改变元素的类型,再写入数据。

    具体方法:cy.get('#hr').then((e1)=>{

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

    }).type('值')

    2、input标签属性为readonly时写入数据

    <input type=text,id='hr',readonly.......>向这个元素中写入数据的时候,可以先删除元素readonly再写入

    解决方法:使用removeAttr()方法,改变元素的类型,再写入数据。

    具体方法:cy.get('#hr').then((e1)=>{el.removeAttr('readonly')}).type('值')

    3、界面元素遮挡的情况下如何写入数据

    有时候,我们在界面中输入数据时,例如下拉框正好挡住了要写的输入框,cypress可能就无法找到元素,使用强制输入的方法{force:true}.

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

    此方法在点击时也可以使用,click({force:true}).

  • 相关阅读:
    Http record java
    Java String constructed from byte array has bad length
    Schema
    Scale-up(纵向扩展) vs Scale-out(横向扩展)
    数据同步
    JDBC and Oracle conn.commit and conn.setAutocommit not working properly
    DGIM
    Github Blog 搭建手册
    软件探索(一)
    经典书单 —— 人文社科
  • 原文地址:https://www.cnblogs.com/memebuguoshixingfu/p/11941770.html
Copyright © 2020-2023  润新知