Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

429
Vistas
Clicking cookie button with Selenium 4 error: object[] has no size and location

I've been attempting to click a button in a pop-up with selenium, but I'm getting the following error:

object [HTMLDivElement] has no size and location

I have tried the normal way, with just click, since it is in the viewport and I am waiting for the page to fully load:

let pressCookieButton = await driver.findElement(By.xpath('//a[@class="btn-actiune btn-actiune--principal"]/..'))
await pressCookieButton.click();

But this does not work. It says

Element not interactible

Then, i tried to click using actions:

let pressCookieButton = await driver.findElement(By.xpath('//a[@class="btn-actiune btn-actiune--principal"]/..'))
const actions = driver.actions({ async: true });
await actions.click(pressCookieButton).perform();

But i get:

object [HTMLDivElement] has no size and location

The HTML that I am attempting to click is the following:

<div class="col-md-4 col-sm-4 col-xs-12"> 
    <a href="javascript:;" onclick="modCookies.updatePermisiuniCookies('toate');" class="btn-actiune btn-actiune--principal">Accept toate cookie-urile</a>  
</div>

Below is the full code:

const {Builder} = require('selenium-webdriver');
const {By} = require('selenium-webdriver');

(async function helloSelenium() {

    let driver = await new Builder().forBrowser('chrome').build();

    try{

        await driver.get('https://www.imobiliare.ro/vanzare-apartamente/timisoara/matei-basarab/apartament-de-vanzare-3-camere-XCB61020C');
    
        await driver.sleep(7000);
        console.log("clicking")
    
        
        let pressCookieButton = await driver.findElement(By.xpath('//a[@class="btn-actiune btn-actiune--principal"]/..'))

        
        const actions = driver.actions({ async: true });
        await actions.click(pressCookieButton).perform();
    
        //findElement(By.className('btn-actiune btn-actiune--principal'));
        await driver.sleep(10000);
    
        await pressCookieButton.click();
    
    }catch(error){
        console.log(error)

        await driver.sleep(5000);

        // await driver.quit()
    }
    
})();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As you can see from the GIF below, the xpath matches two elements and by using driver.findElement you are selecting the first one, while the correct one is the second.

So you should either use driver.findElements instead of driver.findElement and then select the second element, or use a selector targetting only the correct element, such as

driver.findElement(By.cssSelector('div[class*="vizibil-informare"] a[class*="principal"]'))

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda