2016-12-14 74 views
1

我有硒的Java测试,应该点击一个元素,但我得到了以下错误:Selenium测试失败“元素不是在点击......”

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 ... 

的问题是,这个测试应该等待对于覆盖到disapear 叠加出现在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)); 

回答

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网络元素