如何求解cy.type()失败,因为它针对残疾元素

发布于 2025-02-10 17:50:25 字数 2424 浏览 1 评论 0原文

我正在通过命令命令访问我的Gmail帐户。 .js。 此后我可以登录,但是柏树给我带来了一个错误 cy.type()失败了,因为它针对了残疾元素。

commands.js

/// <reference types="cypress" 
import { parseString } from "xml2js";
Cypress.Commands.add('loginByGoogleApi', () => {  
  cy.request({
    method: 'POST',
    url: 'https://www.googleapis.com/oauth2/v4/token',
    body: {
      grant_type: 'refresh_token',
      client_id:  Cypress.env('googleClientId'),
      client_secret:  Cypress.env('googleClientSecret'),
      refresh_token:  Cypress.env('googleRefreshToken'),
    },   
  }).then(({ body }) => {
    const { access_token, id_token } = body
    cy.log('Opening emails including code to verify')
    cy.request({
      method: 'GET',
      url: 'https://mail.google.com/mail/feed/atom/verifyCode',
      headers: { Authorization: Bearer ${access_token} },
    }).then(({ body }) => {
      parseString(body, function (err, results) {
        let data = JSON.stringify(results)
        let codeTitle = JSON.parse(data).feed.entry[0].title[0];
        let code = codeTitle.replace('Chaine confirmation code: ','');
        cy.log(code)
      });
    });   
  })
})

testfile.cy.cy.js

const { Code } = require("@chaine/keychaine");


describe('Open login page', () => {   
  it('Enter your email to login', () => {
    cy.visit('https://chaineapp.com/staging/login%27)
    cy.get('#field-1').click().type('[email protected]');
    cy.get('[class*="chakra-button css-yg51i0"]').click();
    cy.get('#pin-input-2-0').type(<need to put code here>);
    })   
  it('get code', () => {
    cy.loginByGoogleApi()

  }) 
})

cypresserror

cy.type()失败了,因为它针对残疾元素。

输入的元素是:

<input aria-label="Please enter your pin code" inputmode="numeric" type="tel" id="pin-input-2-5" autocomplete="one-time-code" placeholder="" class="chakra-pin-input css-jyb0wy" value="1" data-index="5" disabled="">

确保该元素在输入它之前没有命名为禁用的属性。

错误的图像

I am accessing my Gmail account by command loginByGoogleApi under commands.js, then getting the requested email body and pulling the required data from the body, and saving it in a const variable code typing the pulled email data (code) in my testFile.cy.js.
I am able to login after this but cypress throwing me an error cy.type() failed because it targeted a disabled element.

commands.js

/// <reference types="cypress" 
import { parseString } from "xml2js";
Cypress.Commands.add('loginByGoogleApi', () => {  
  cy.request({
    method: 'POST',
    url: 'https://www.googleapis.com/oauth2/v4/token',
    body: {
      grant_type: 'refresh_token',
      client_id:  Cypress.env('googleClientId'),
      client_secret:  Cypress.env('googleClientSecret'),
      refresh_token:  Cypress.env('googleRefreshToken'),
    },   
  }).then(({ body }) => {
    const { access_token, id_token } = body
    cy.log('Opening emails including code to verify')
    cy.request({
      method: 'GET',
      url: 'https://mail.google.com/mail/feed/atom/verifyCode',
      headers: { Authorization: Bearer ${access_token} },
    }).then(({ body }) => {
      parseString(body, function (err, results) {
        let data = JSON.stringify(results)
        let codeTitle = JSON.parse(data).feed.entry[0].title[0];
        let code = codeTitle.replace('Chaine confirmation code: ','');
        cy.log(code)
      });
    });   
  })
})

testFile.cy.js

const { Code } = require("@chaine/keychaine");


describe('Open login page', () => {   
  it('Enter your email to login', () => {
    cy.visit('https://chaineapp.com/staging/login%27)
    cy.get('#field-1').click().type('[email protected]');
    cy.get('[class*="chakra-button css-yg51i0"]').click();
    cy.get('#pin-input-2-0').type(<need to put code here>);
    })   
  it('get code', () => {
    cy.loginByGoogleApi()

  }) 
})

CypressError

cy.type() failed because it targeted a disabled element.

The element typed into was:

<input aria-label="Please enter your pin code" inputmode="numeric" type="tel" id="pin-input-2-5" autocomplete="one-time-code" placeholder="" class="chakra-pin-input css-jyb0wy" value="1" data-index="5" disabled="">

Ensure the element does not have an attribute named disabled before typing into it.

image of error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巨坚强 2025-02-17 17:50:25

您可以添加force:true type以禁用可操作性检查 -

cy.get('#pin-input-2-0').type('text to type', {force: true});

You can add force: true with type to disable actionability checks -

cy.get('#pin-input-2-0').type('text to type', {force: true});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文