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

344
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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