Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

318
Visualizações
Clicking over hidden element in Cypress is not working

I am running into this problem without finding a good solution. I tried every post that I found in Google but without success. I am isolating the problem so I can share you the exact point. I am searching an specific product in "mercadolibre.com" and I want to sort the list from the lower price to the maximum. To do so you can enter directly here and clicking over the option "Menor Precio".

enter image description here

Doing manually this just works fine but with Cypress I am not being able to do that. This script just runs fine but the last step seems to have no effect.

// Activate intelligence
/// <reference types="Cypress" />

describe("Main test suite for price control", () => {
    it("search scanners and order them by ascending price", () => {
      // Web access
      cy.visitAndWait("https://listado.mercadolibre.com.ar/scanner-blueetooth#D[A:scanner%20blueetooth");

      // Order by ascending price
      cy.get(':nth-child(2) > .andes-list__item-first-column > .andes-list__item-text > .andes-list__item-primary').click({force: true})
    });
});;

Maybe Am I using a bad approach to refer the object?

Best regards!

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You may have noticed the polite discussion about dismissing the popups, is it necessary or not.

I believe not, and to rely on dismissing the popups will give a flaky test.

I also think the issue is as @DizzyAl says, the event handler on the dropdown button is not attached until late in the page load.

This is what I tried, using retries to give a bit more time for page loading.


Cypress.on('uncaught:exception', () => false)

before(() => {
  cy.visit('http://mercadolibre.com.ar')
  cy.get(".nav-search-input").type("scanner bluetooth para auto{enter}");
  cy.get('.ui-search-result__wrapper')  // instead of cy.wait(3000), wait for the list
})

it('gets the dropdown menu on 1st retry', {retries: 2}, () => {

  // Don't dismiss the popups

  cy.get('button.andes-dropdown__trigger').click()
  cy.contains('a.andes-list__item', 'Menor precio').click()

  // page reload happens
  cy.contains('.ui-search-result__wrapper:nth-child(1)', '$490', {timeout:20000})
});
about 4 years ago · Juan Pablo Isaza Relatório

0

I would retry menu until options become visible

Cypress.on('uncaught:exception', () => false)

before(() => {
  cy.visit('https://listado.mercadolibre.com.ar/scanner-blueetooth#D%5BA:scanner%20blueetooth%5D') 
})

it('retries the menu open command', () => {

  function openMenu(attempts = 0) {
    if (attempts > 6) throw 'Failed open menu'

    return cy.get('button.andes-dropdown__trigger').click()
      .then(() => {
        const option = Cypress.$('.andes-list:visible') // is list visible
        if (!option.length) {
          openMenu(++attempts)  // try again, up to 6 attempts
        } 
      })
  } 

  openMenu().then(() => {
    cy.get('a.andes-list__item:contains(Menor precio)').click()
  })

  // Verification
  cy.contains('.ui-search-result__wrapper:nth-child(1)', '$490', {timeout:20000})
})
about 4 years ago · Juan Pablo Isaza Relatório

0

It looks like the click event is being added to the dropdown button late, and the click is failing.

See When Can The Test Start? for an discussion.

I tried to adapt the code in the article, but couldn't get it to work.

However, adding a cy.wait() or a cy.intercept() for the last network call works.

cy.intercept('POST', 'https://bam-cell.nr-data.net/events/**').as('events')
cy.visit('https://listado.mercadolibre.com.ar/scanner-blueetooth#D%5BA:scanner%20blueetooth%5D')
cy.wait('@events', {timeout: 20000})

// Page has loaded, verify the top item price
cy.contains('.ui-search-result__wrapper:nth-child(1)', '$1.385')

// Open the sort-by dropdown
cy.get('button.andes-dropdown__trigger').click()

// Choose sort-by lowest price
cy.contains('a.andes-list__item', 'Menor precio').click()

// Verify first item has different price, long timeout to wait for page re-load
cy.contains('.ui-search-result__wrapper:nth-child(1)', '$490', {timeout:20000})

You may be able to shorten the page load wait by picking a different network call to wait on.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda