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

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

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