我有 3 次等待:
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='pagecontrols']/input[1]")));
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='pagecontrols']/input[1]")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='pagecontrols']/input[1]")));
对于相同的元素,但等待之后,当我想点击时
driver.findElement(By.xpath("//*[@id='pagecontrols']/input[1]")).click();
我有:
"Element (...) is not clickable at point"
我试图通过添加此部分来等待 JavaScript 完全加载
public void waitForLoad(WebDriver driver)
{
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>()
{
public Boolean apply(WebDriver driver)
{
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}
但是这不起作用(这在不同的地方有帮助,所以通常这在某些情况下有帮助),也许我做错了什么? 我想我也应该等待 jQuery,但说实话,我确实知道怎么做(我已经找到了一些解决方案,但它们对我不起作用)
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element <input type="button" class="btn btn-default" data-toggle="modal" data-target="#adduser" data-localize="adduser" value="Add user"> is not clickable at point (1397, 97). Other element would receive the click: <div class="blockUI blockOverlay" style="z-index: 1000; border: none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); cursor: wait; position: absolute; opacity: 0.304712;"></div>
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 149 milliseconds
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'BTIS1000062581', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_20'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=C:\Users\user\AppData\Local\Temp\scoped_dir7068_2467}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: e9c9bf2150b10d2865e7a117c1c9e739
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:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at automationFramework.FirstTestCase.main(FirstTestCase.java:201)
还有一件事:当我添加时 线程.sleep(500); 在单击元素之前它正在工作,但我想摆脱这些 sleep
最佳答案
避免这种“烟雾”UI 阻塞的唯一真正有效的方法是使用 Thread.sleep(); 3000 毫利斯,瞧!
关于javascript - Selenium: "is not clickable at point"如何等待所有脚本加载完毕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41822744/