硒测试失败"元素无法点击..."

时间:2016-12-14 15:35:31

标签: java selenium selenium-webdriver

我有一个selenium java测试应该点击一个元素,但是我收到以下错误:

org.openqa.selenium.WebDriverException: Element is not clickable at point (1123, 355). Other element would receive the click: <img src="/vdoc/images/transp.gif" height="100%" width="100%">
Command duration or timeout: 178 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'VM-DEV-SELENIUM', ip: '192.168.60.216', os.name: 'Windows Server 2012', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e74f1926-e4a0-4326-8e35-3ea31797308c
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    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 ...

问题是测试应该等待覆盖消失 叠加层存在于DOM中并使用z-index:

<div id="ui-loader-background" class="ui-loader-background" style="display: none; position: fixed; z-index: 9999; top: 0px; left: 0px; width: 2032px; height: 1034px;">
    <img width="100%" height="100%" src="/tata/images/transp.gif">
    <div class="ui-loader" style="position: fixed; left: 843.5px; top: 487px;">
        <div class="ui-loading">
            <span>Veuillez patienter ...</span>
        </div>
    </div>
</div>

我正在使用以下CSS选择器在DOM中查找我的元素:

.screen.platform.vui-screen-explorer.EzsSite-browse table > tbody > tr:nth-child(13) > td:nth-child(2) > a:nth-child(2)

使用此代码:

WebElement element = new WebDriverWait(driver, 15000)
                .until(ExpectedConditions.elementToBeClickable(By.cssSelector(cssSelector)));
element.click();

在找到我的元素之前,我已经尝试等待叠加层的隐身,但它不起作用:

By loadingImage = By.ByCssSelector.className(".ui-loader-background");

        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(10, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

        wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));

1 个答案:

答案 0 :(得分:0)

使用ExpectedConditions.invisibilityOfElementLocated等待叠加层消失是个好主意,但是您试图摆脱具有<div>属性的style="display: none",因此它最初是不可见的。此外,如果您检查异常日志:Other element would receive the click: <img src="/vdoc/images/transp.gif" height="100%" width="100%">,则不会提及所需元素div,而是img

因此,请尝试使用CSS selector 'img[src="/tata/images/transp.gif"]'来定义loadingImage网络元素