Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

427
Views
Al hacer clic en el botón de cookies con el error de Selenium 4: el objeto [] no tiene tamaño ni ubicación

He estado intentando hacer clic en un botón en una ventana emergente con selenio, pero recibo el siguiente error:

 object [HTMLDivElement] has no size and location

Lo he intentado de la manera normal, con solo hacer clic, ya que está en la ventana gráfica y estoy esperando que la página se cargue por completo:

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

Pero esto no funciona. Dice

 Element not interactible

Luego, traté de hacer clic usando acciones:

 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();

pero obtengo:

 object [HTMLDivElement] has no size and location

El HTML en el que intento hacer clic es el siguiente:

 <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>

A continuación se muestra el código completo:

 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 answers
Answer question

0

Como puede ver en el GIF a continuación, el xpath coincide con dos elementos y al usar driver.findElement está seleccionando el primero, mientras que el correcto es el segundo.

Por lo tanto, debe usar driver.findElements en lugar de driver.findElement y luego seleccionar el segundo elemento, o usar un selector que apunte solo al elemento correcto, como

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

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!