“元素在点上无法点击”,只有Chrome,任何等待都不起作用

时间:2016-11-23 10:25:51

标签: selenium selenium-webdriver selenium-chromedriver

我在Eclipse中有这个错误

    org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (288, 196). Other element would receive the click: <div style="display: block; opacity: 0.00664228; z-index: 3001; position: absolute; cursor: wait; background-color: white; width: 1536px; height: 771px; top: 0px; left: 0px; border-radius: 0px;" dojoattachpoint="_underlayNode"></div>
      (Session info: chrome=54.0.2840.99)
      (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 38 milliseconds
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
    System info: host: 'ADMINIB-JIGAGHP', ip: '9.164.178.163', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\Users\IBM_AD~1\AppData\Local\Temp\scoped_dir10616_4624}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.99, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
    Session ID: 6abd80443ba6dbea601d80248a4c8485
        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:206)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
        at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85)
        at Tasks.CategoryHandler.editCategory(CategoryHandler.java:152)
        at TestCases.LogInEditCategory.editCategory(LogInEditCategory.java:21)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
        at org.testng.TestRunner.privateRun(TestRunner.java:774)
        at org.testng.TestRunner.run(TestRunner.java:624)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
        at org.testng.SuiteRunner.run(SuiteRunner.java:261)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
        at org.testng.TestNG.run(TestNG.java:1048)
        at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

我正在使用Selenium 2.5,它适用于FireFox,但不适用于Chrome。我尝试了很多选项,但没有一个可行。

            WebDriverWait wait = new WebDriverWait(driver, 120);

            WebElement element = wait.until(ExpectedConditions
                    .elementToBeClickable(By.xpath(".//*[@id='bg_widget_AssetListItem_0']/div[1]/input")));
            //driver.manage().timeouts().pageLoadTimeout(120,TimeUnit.SECONDS);
            // driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
            //Thread.sleep(2000);

            driver.findElement(By.xpath(".//*[@id='bg_widget_AssetListItem_0']/div[1]/input")).click();

只有Thread.sleep(2000)对我有用,但我知道这不是一个好选择。 那么我可以做些什么来处理超时或等待?

1 个答案:

答案 0 :(得分:0)

我想当你的页面加载正在进行时会出现像this这样的模态窗口。 Webdriver无法识别它并单击按钮,此时该按钮实际上无法点击。这似乎是众所周知的chromedriver问题。

正如您所提到的,您可以使用强制等待,例如Thread.sleep(2000),或等到模态窗口disappeared

new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath('//div[@style="display: block; opacity: 0.00664228; z-index: 3001; position: absolute; cursor: wait; background-color: white; width: 1536px; height: 771px; top: 0px; left: 0px; border-radius: 0px;"]'))));