嘿,我有一个我想解决很长时间的问题。 问题是我希望硒在屏幕上显示一条消息后等待元素可单击。
这是我的主要爱好
BasePage.waitInvisabilityOfElementByXpath("//div[@class='ant-notification ant-notification-topRight']");
System.out.println("\n\n Finished first wait \n\n ");
By locator;
locator = By.id("header-account");
BasePage.waitForClickable(locator,15500);
System.out.println("\n\n Finished second wait \n\n ");
LoginHomeManager.logoutNoSleep();
我有创建的这种方法:
public static void waitForClickable(By locator, int timeOut) throws Exception {
WebDriver driver = WebDriverMgr.getDriver();
driver.manage().timeouts().implicitlyWait(IMPLICIT_WAITE, TimeUnit.SECONDS);
Instant now = Instant.now();
while (Instant.now().isBefore(now.plusSeconds(timeOut)))
{
try
{
new WebDriverWait(driver, timeOut).until(ExpectedConditions.elementToBeClickable(locator));
return;
}
catch (WebDriverException e)
{
// do nothing, loop again
}
}
throw new Exception("Not able to click element <" + locator + "> within " + timeOut + "s.");
}
我收到此错误:
** Click Avatar by ID: header-account
Sun Oct 27 11:58:05 IST 2019:INFO: WebDriver: Click on [[ChromeDriver: chrome on XP (e22c7e2f4d7f1c4bb8abf664a7f53366)] -> id: header-account]
Sun Oct 27 11:58:05 IST 2019:ERROR: element click intercepted: Element <button _ngcontent-iib-c11="" class="avatar-style ant-btn ant-btn-default ant-btn-circle" id="header-account" nz-button="" nz-popover="" nzplacement="bottomRight" nzshape="circle" nztrigger="click" ng-reflect-nz-shape="circle" ng-reflect-nz-content="[object Object]" ng-reflect-nz-trigger="click" ng-reflect-nz-placement="bottomRight" ng-reflect-directive-name-title="" nz-wave="[object Object]">...</button> is not clickable at point (1888, 31). Other element would receive the click: <path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path>
(Session info: chrome=78.0.3904.70)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PC', ip: '10.9.25.7', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.70, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:\Users\AppData\Local...}, goog:chromeOptions: {debuggerAddress: localhost:60679}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: e22c7e2f4d7f1c4bb8abf664a7f53366
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <button _ngcontent-iib-c11="" class="avatar-style ant-btn ant-btn-default ant-btn-circle" id="header-account" nz-button="" nz-popover="" nzplacement="bottomRight" nzshape="circle" nztrigger="click" ng-reflect-nz-shape="circle" ng-reflect-nz-content="[object Object]" ng-reflect-nz-trigger="click" ng-reflect-nz-placement="bottomRight" ng-reflect-directive-name-title="" nz-wave="[object Object]">...</button> is not clickable at point (1888, 31). Other element would receive the click: <path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path>
(Session info: chrome=78.0.3904.70)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PC', ip: '10.9.7.5', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.70, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:\Users\AppData\Local...}, goog:chromeOptions: {debuggerAddress: localhost:60679}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: e22c7e2f4d7f1c4bb8abf664a7f53366
然后发生此异常:
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
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 sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.lambda$new$0(EventFiringWebDriver.java:404)
at com.sun.proxy.$Proxy6.click(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:417)
at com.blinkx.rx.ui.common.abstractionLayer.HomePage.clickAvatarNoSleep(HomePage.java:215)
at com.blinkx.rx.ui.common.abstractionLayer.HomePage.clickLogoutNoSleep(HomePage.java:221)
at com.blinkx.rx.ui.common.areaLibrary.LoginHomeManager.logoutNoSleep(LoginHomeManager.java:223)
at com.blinkx.rx.ui.common.tests.EXPublisherSignUp.FinalPUbOpsApproval(EXPublisherSignUp.java:244)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
在领事中打印 System.out.println(“ \ n \ n完成第二次等待\ n \ n”);
意味着它应该是可单击的并且该功能有效,但是实际上不起作用。
这是用户界面 我希望硒等待显示的消息,然后按圆圈图标并注销。
这是我手动期望的
网站是有角的
答案 0 :(得分:0)
该元素是部分可见的,因此ExpectedConditions.elementToBeClickable
通过。它检查元素是否可见(是)和已启用(usually true)。
Selenium尝试单击元素的中心,该元素被成功消息覆盖,因此是异常
ElementClickInterceptedException: element click intercepted: Element <button id="header-account" is not clickable at point (1888, 31). Other element would receive the click: ...
您需要关闭成功消息并等待其消失,然后再单击按钮
WebDriverWait wait = new WebDriverWait(driver, timeOut);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("i.anticon.ant-notification-close-icon.anticon-close > svg")));
element.click();
wait.until(ExpectedConditions.invisibilityOf(element));