Селен не дожидается, пока элемент станет кликабельным - PullRequest
0 голосов
/ 27 октября 2019

Привет всем, у меня есть проблема, которую я пытаюсь решить в течение длительного времени. Проблема в том, что я хочу, чтобы селен ждал, пока элемент будет активен после сообщения, отображаемого на экране.

  • Идентификатор элемента: header-account
  • Время ожидания, которое я отправилМетод: 15500
  • Я установил неявное ожидание: IMPLICIT_WAITE = 35;
  • Как вы можете видеть, селен не ждет секунду

Это мой главный:

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");

Это означает, что он должен быть активным, и функция работала,однако на самом деле это не работает.

Это пользовательский интерфейс, который я хочу, чтобы selenium подождал, пока не отобразится сообщение, а затем нажмите значок круга и выйдите из системы. enter image description here

Это то, что я ожидал вручную

enter image description here

Сайт угловой

1 Ответ

0 голосов
/ 27 октября 2019

Элемент частично виден, поэтому ExpectedConditions.elementToBeClickable pass. Он проверяет, является ли элемент видимым (он есть) и включен (который обычно истинен ).

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));    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...