0

I had tried to click a button tried with its id, CSS and XPath which is available through findElement but does not perform the action upon click. Here is the sample code and follows the exception as well.

  WebElement PageSpeedTestbutton1 = driver.findElement(By.cssSelector("#files")); 
            System.out.println("Found");    
            WebElement PageSpeedTestbutton2 = driver.findElement(By.xpath("//input[@id='files']"));
            System.out.println("Found");    
            PageSpeedTestbutton1.click();
            PageSpeedTestbutton2.click();
            System.out.println("Clicked Checker");



Results:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (-451, 258)
  (Session info: chrome=73.0.3683.103)
  (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'RAUNAK-MA', ip: '192.168.2.200', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.46.628402 (536cd7adbad73a..., userDataDir: C:\Users\RAUNAK~1.MAS\AppDa...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:64017}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.103, webStorageEnabled: true}
Session ID: da5b790c67ddae03940ff612653dfbb7
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    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 newpackage1.newTest.main(newTest.java:87)
User008
  • 377
  • 3
  • 18

1 Answers1

1

The following Error suggest that your element is available but not clickable.

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point 

Try below code it should work.

WebElement PageSpeedTestbutton1 = driver.findElement(By.cssSelector("#files")); 

Actions action = new Actions(driver);
action.moveToElement(PageSpeedTestbutton1).click().build().perform();

OR

WebElement PageSpeedTestbutton1 = driver.findElement(By.cssSelector("#files")); 

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", PageSpeedTestbutton1);

EDITED

List<WebElement> PageSpeedTestbuttons = driver.findElements(By.cssSelector("#files"));
        if (PageSpeedTestbuttons.size()>0)
        {
            WebElement PageSpeedTestbutton1 =PageSpeedTestbuttons.get(0); 
            Actions action = new Actions(driver);
            action.moveToElement(PageSpeedTestbutton1).click().build().perform();
        }
        else
        {
            System.out.println("Element is not available");
        }
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • Currently, when I put both the scripts of Actions and JS Executor it works when one of them is missing it does not work. I don't know why it is acting weird though. – User008 Apr 18 '19 at 10:13
  • 1
    in that case you need to share your link to get to the bottom of that.Or first take the lenght count of the element if it not zero then perform above operation if not pass on message element is not avaialable. – KunduK Apr 18 '19 at 10:24
  • @User008 : Try Edited options. – KunduK Apr 18 '19 at 10:36
  • The type List is not generic; it cannot be parameterized with arguments – User008 Apr 19 '19 at 02:24