0

I am using selenium java and i have applied explicit wait command on script , so here is the scenario the page is taking few mille seconds to load and internet speed on my office is too fast as a result script cant find element to be clickable , if i apply sleep.thread then it works but i dont want to use sleep so thats why my explicit wait is not working according to my needs not sure how to resolve this , i am sharing my console error message and script as well

ChromeOptions optionsBeta = new ChromeOptions();
             optionsBeta.setBinary("C:\\Program Files\\Google\\Chrome Beta\\Application\\chrome.exe");
             System.setProperty("webdriver.chrome.driver" , "./Driver/chromedriver.exe");
             driver = new ChromeDriver(optionsBeta);
            // WebDriverManager.chromedriver().setup();
             waits=new WebDriverWait (driver, Duration.ofSeconds(10));



 waits.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[id='react-select-regionId--value'] div[class='Select-value']")));
               waits.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[id='react-select-regionId--value'] div[class='Select-value']")));
               // Thread.sleep(500);
               driver.findElement(By.cssSelector("div[id='react-select-regionId--value'] div[class='Select-value']")).click();




FAILED: First_Test.Task_TestNG.CheckOutTest
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <div class="Select-value">...</div> is not clickable at point (746, 348). Other element would receive the click: <div class="LoadingOverlay">...</div>
  (Session info: chrome=104.0.5112.48)
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'AWAIS-PC', ip: '192.168.1.62', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [2d991cd12a3008b98e6c0b82f0f7d750, clickElement {id=0ef92db0-9a11-4eed-8567-7a29f9098752}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 104.0.5112.48, chrome: {chromedriverVersion: 104.0.5112.29 (eff877e18f76..., userDataDir: C:\Users\WRP\AppData\Local\...}, goog:chromeOptions: {debuggerAddress: localhost:57616}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:57616/devtoo..., se:cdpVersion: 104.0.5112.48, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Element: [[ChromeDriver: chrome on WINDOWS (2d991cd12a3008b98e6c0b82f0f7d750)] -> css selector: div[id='react-select-regionId--value'] div[class='Select-value']]
Session ID: 2d991cd12a3008b98e6c0b82f0f7d750
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:257)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:78)
    at First_Test.Task_TestNG.CheckOutTest(Task_TestNG.java:144)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
    at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:677)
    at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
    at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
    at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:962)
    at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
    at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
    at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.testng.TestRunner.privateRun(TestRunner.java:806)
    at org.testng.TestRunner.run(TestRunner.java:601)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:433)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:427)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:387)
    at org.testng.SuiteRunner.run(SuiteRunner.java:330)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
    at org.testng.TestNG.runSuites(TestNG.java:1099)
    at org.testng.TestNG.run(TestNG.java:1067)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
===============================================

[main] INFO org.testng.internal.Utils - [TestNG] Time taken by org.testng.internal.ExitCodeListener@43fda8d9: 0 ms
Zamir Sultan
  • 41
  • 1
  • 6
  • Does this answer your question? [org.openqa.selenium.ElementClickInterceptedException: element click intercepted error using Selenium and Java in headless mode](https://stackoverflow.com/questions/62260511/org-openqa-selenium-elementclickinterceptedexception-element-click-intercepted) – G. Victor Jul 21 '22 at 18:47

2 Answers2

0

The exception says clearly there is another overlaying element.

org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <div class="Select-value">...</div> is not clickable at point (746, 348). Other element would receive the click: <div class="LoadingOverlay">...</div>

Instead of waiting on <div class="Select-value">...</div> to be clickable, wait to <div class="LoadingOverlay">...</div> be not visible.

pburgr
  • 1,722
  • 1
  • 11
  • 26
  • whats is the proper code for this purpose – Zamir Sultan Jul 20 '22 at 08:57
  • `new WebDriverWait(driver, 30).until(ExpectedConditions.invisibilityOfElementLocated(By.by));` – pburgr Jul 20 '22 at 09:10
  • so this is how my code should look like waits.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("//div[@id='react-select-regionId--value']//div[@class='Select-value']"))); driver.findElement(By.cssSelector("//div[@id='react-select-regionId--value']//div[@class='Select-value']")).click(); – Zamir Sultan Jul 20 '22 at 11:50
  • i have asked a detail question in this may be you can give a better answer https://stackoverflow.com/questions/73052234/access-div-element-which-is-inside-a-label-element-how-can-i-access-child-elem – Zamir Sultan Jul 21 '22 at 08:42
0

The error says that the click on the desired element was intercepted (blocked) by another element" ..." that is located above your element to click. You should wait until the loader will disappear, then wait and click on your element.

waits.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div[class='LoadingOverlay']")));

As result final code will be the next:

waits.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[id='react-select-regionId--value'] div[class='Select-value']")));
waits.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div[class='LoadingOverlay']")));
waits.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[id='react-select-regionId--value'] div[class='Select-value']")));
driver.findElement(By.cssSelector("div[id='react-select-regionId--value'] div[class='Select-value']")).click();
G. Victor
  • 545
  • 1
  • 6
  • 17