1

First of all, I'm using Cucumber 4.2 and Selenium 3 on Firefox 64.

I'm trying to get past the "Accept cookies" button with Selenium, but nothing seems to work. I've tried following DebanjanB's solution to this error, but without any luck.

Here's my code:

String btnLocation = new String("/html/body/div[1]/div[2]/div[4]/div[2]/div");
WebDriverWait wait15 = new WebDriverWait(driver, 15);
wait15.until(ExpectedConditions.elementToBeClickable(By.xpath(btnLocation)));
driver.findElement(By.xpath(btnLocation)).click();

And this is the error trace:

    And I have accepted the cookies                     # Stepdefs.i_have_accepted_the_cookies()
  org.openqa.selenium.ElementNotInteractableException: Element <div class="optanon-alert-box-button-middle accept-cookie-container"> could not be scrolled into view
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'DESKTOP-KS4A1NQ', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 64.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 28204, moz:profile: C:\Users\cian\AppData\Loca..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 30433d1c-d85b-45d6-b65e-076d3e04f3ec
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
        at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
        at [org_name].cucumber_ex.Stepdefs.i_have_accepted_the_cookies(Stepdefs.java:55)
        at ?.I have accepted the cookies([org_name]/cucumber_ex/Navigate_Menu_Categories.feature:26)

    When I roll my mouse over a category                # Stepdefs.i_roll_my_mouse_over_a_category()
    And the dropdown menu appears                       # Stepdefs.the_dropdown_menu_appears()
    And I click a subcategory                           # Stepdefs.i_click_a_subcategory()
    Then I should be brought to that subcategory's page # Stepdefs.i_should_be_brought_to_that_subcategory_s_page()

Failed scenarios:
[org_name]/cucumber_ex/Navigate_Menu_Categories.feature:24 # User wants to pick a product category

1 Scenarios (1 failed)
6 Steps (1 failed, 4 skipped, 1 passed)
0m8.878s

org.openqa.selenium.ElementNotInteractableException: Element <div class="optanon-alert-box-button-middle accept-cookie-container"> could not be scrolled into view
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'DESKTOP-KS4A1NQ', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 64.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 28204, moz:profile: C:\Users\cian\AppData\Loca..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 30433d1c-d85b-45d6-b65e-076d3e04f3ec
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
        at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
        at [org_name].cucumber_ex.Stepdefs.i_have_accepted_the_cookies(Stepdefs.java:55)
        at ?.I have accepted the cookies([org_name]/cucumber_ex/Navigate_Menu_Categories.feature:26)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 9.104 sec <<< FAILURE!
User wants to pick a product category(Navigate menu categories)  Time elapsed: 8.748 sec  <<< ERROR!
org.openqa.selenium.ElementNotInteractableException: Element <div class="optanon-alert-box-button-middle accept-cookie-container"> could not be scrolled into view
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'DESKTOP-KS4A1NQ', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 64.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 28204, moz:profile: C:\Users\cian\AppData\Loca..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 30433d1c-d85b-45d6-b65e-076d3e04f3ec
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
        at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
        at [org_name].cucumber_ex.Stepdefs.i_have_accepted_the_cookies(Stepdefs.java:55)
        at ?.I have accepted the cookies([org_name]/cucumber_ex/Navigate_Menu_Categories.feature:26)


Results :

Tests in error:
  User wants to pick a product category(Navigate menu categories): Element <div class="optanon-alert-box-button-middle accept-cookie-container"> could not be scrolled into view(..)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.302 s
[INFO] Finished at: 2019-01-11T12:41:05Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project cucumber-ex: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\cian\Documents\GitHub\Cucumber-Assignment\cucumber-ex\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project cucumber-ex: There are test failures.

Please refer to C:\Users\cian\Documents\GitHub\Cucumber-Assignment\cucumber-ex\target\surefire-reports for the individual test results.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to C:\Users\cian\Documents\GitHub\Cucumber-Assignment\cucumber-ex\target\surefire-reports for the individual test results.
    at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution (SurefireHelper.java:83)
    at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary (SurefirePlugin.java:176)
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary (SurefirePlugin.java:150)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:650)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:586)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

I tried changing the third line of my code to:

List<WebElement> elList = wait15.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(btnLocation)));
System.out.println("Elements found: " + elList.size());
for(WebElement el : elList) {
System.out.println(el.toString());
}

...to make sure that element existed, and it did.

What am I doing wrong?

EDIT: I should add, I used "Inspect element" to get the Xpath of the "Accept cookies" button. I've also tried copying that button's class, but when I search for that class in the webpage's source code, not even the word "accept" can be found in it, let alone the class name.

EDIT 2.0 To answer Recep's comment, here's the button's HTML:

<div class="optanon-alert-box-button-middle accept-cookie-container" style="">
<a class="optanon-allow-all accept-cookies-button" title="Accepter les cookies" aria-label="Accepter les cookies" role="button" href="javascript:void(0);" onclick="Optanon.TriggerGoogleAnalyticsEvent('OneTrust Cookie Consent', 'Banner Accept Cookies');" tabindex="3">Accepter les cookies</a>
</div>
CiaranC94
  • 176
  • 4
  • 20

2 Answers2

0

the exception states "could not be scrolled into view". when you run it, do you actually see the target button on screen? have you tried adding a step to scroll the item into view? I don't know how to do that with java and cucumber, but with python it's something like:

driver.execute_script("return arguments[0].scrollIntoView(true);", button_element_to_click)
Breaks Software
  • 1,721
  • 1
  • 10
  • 15
  • Yes, I can see the target button. – CiaranC94 Jan 11 '19 at 14:27
  • `scrollIntoView()` the **Accept cookies** button? – undetected Selenium Jan 11 '19 at 14:46
  • I've tried that, but the button doesn't get clicked. – CiaranC94 Jan 11 '19 at 14:51
  • what is the error you get when you attempt the click after scrolling into view? – Breaks Software Jan 11 '19 at 16:31
  • I get told that `org.openqa.selenium.ElementNotInteractableException: Element
    could not be scrolled into view`, I've tried scrolling both the button and the cookie alert into view but neither work
    – CiaranC94 Jan 11 '19 at 16:41
  • my only thought at the moment is that there are multiple buttons matching that btnLocation and so it's trying to click a different one than the one you're actually seeing. is your elList more than one item? – Breaks Software Jan 11 '19 at 17:00
  • No, it just contains 1. I used "Inspect Element" on the "Accept cookies" button so I could copy its Xpath for fetching any elements with said Xpath, and every time only the "Accept cookies" button would correspond to that. – CiaranC94 Jan 11 '19 at 17:28
0

you can simply use OneTrust.AllowAll()

Josen
  • 1
  • 3