3

I am a newbie to selenium automation and I am trying to run this test script. Unfortunately, a cookie consent kept popping up which I believe is obstructing my script from completing. How do I perse the condition to accept the cookie in my script.

FirefoxDriverManager.getInstance().setup();
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.sugarcrm.com/au/request-demo/");
driver.manage().window().maximize();
WebElement ddown = driver.findElement(By.name("firstname"));
Select select = new Select(ddown); 
select.selectByValue("level1");
select.selectByVisibleText("101 - 250 employees");
select.selectByIndex(5);

I do not know how to instruct the script to accept or deny the cookie consent.

1 Answer 1

0

To click on the element Accept All Cookies you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

  • Using cssSelector:

    driver.get("https://www.sugarcrm.com/au/request-demo/");
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll"))).click();
    
  • Using xpath:

    driver.get("https://www.sugarcrm.com/au/request-demo/");
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll']"))).click();
    
  • Browser snapshot:

sugarcrm.com

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.