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

345
Vistas
How can I auto accept cookies pop windows Automation Java

What is the wrong in my code , why auto click doesn't work in accept cookies button. This website using angular application.

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.paulhammant.ngwebdriver.ByAngular;
import com.paulhammant.ngwebdriver.NgWebDriver;

public class NewClass {

public static void main(String[] args) {
    
    System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\Hp\\Downloads\\chromedriver_win32\\chromedriver.exe");
        ChromeDriver driver = new ChromeDriver();
                    NgWebDriver ngWebDriver = new NgWebDriver(driver);
                    ngWebDriver.waitForAngularRequestsToFinish();
        driver.get("https://visa.vfsglobal.com/ind/en/deu/login/");
        ngWebDriver = new NgWebDriver((JavascriptExecutor) driver);
        ngWebDriver.waitForAngularRequestsToFinish();           
        driver.findElement(ByAngular.options("onetrust-accept-btn-handler")).click();
 }

}

Attached Image here Just want to auto click this pop up

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

As per my knowledge there is no way to auto accept cookies using ChromeOptions you need to find the element and click.

driver = new ChromeDriver();
driver.get("https://visa.vfsglobal.com/ind/en/deu/login/");
new WebDriverWait(driver, 30).until(ExpectedConditions.elementToBeClickable(By.id("onetrust-accept-btn-handler"))).click();
over 4 years ago · Santiago Trujillo Denunciar

0

When you use this line

driver.findElement(ByAngular.options("onetrust-accept-btn-handler")).click();

it will try to find the element immediately, often resulting in errors. Cause web element/elements have not been rendered properly.

This is main reason we should opt for Explicit waits, implemented by WebDriverWait.

They allow your code to halt program execution, or freeze the thread, until the condition you pass it resolves. The condition is called with a certain frequency until the timeout of the wait is elapsed. This means that for as long as the condition returns a falsy value, it will keep trying and waiting.

Code :

Webdriver driver = new ChromeDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.id("onetrust-accept-btn-handler"))).click();
over 4 years ago · Santiago Trujillo Denunciar

0

Please add wait functionality before entering username and password,

if pop up interrupt while entering, username and password will not be proper.

In my case, i created a common method wait and click,

   dh.wait_for_the_element_then_do(By.xpath("//button[text()='Accept All Cookies']"), "click", "", "cookies popo up");
   dh.wait_for_the_element_then_do(By.xpath("//input[@tcp-auto='input-username']"),"send", username, "login username");
   dh.wait_for_the_element_then_do(By.xpath("//input[@tcp-auto='input-password']"),"send", password, "login password");
   dh.wait_for_the_element_then_do(By.xpath("//span[text()='Sign in']"),"click", "", "signin button");
over 4 years ago · Santiago Trujillo 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