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