Я получаю сообщение об ошибке для метода isDisplayed? - PullRequest
0 голосов
/ 14 февраля 2020

if (driver.findElement (By.id (id)). IsDisplayed ()) {

}

Всегда не удается выполнить, когда элемент недоступен?

Среда:

Appium 1.15.1

java Клиент 7.3.0

Селен- java 3.141.59

Журналы ошибок:

Android Страницы с проблемами кодирования

org.openqa.selenium.NoSuchElementException: Не удается найти элемент по этой стратегии: By.chained ({By.AccessibilityId: OK}) в io. appium.java_client.pagefactory.AppiumElementLocator.findElement (AppiumElementLocator. java: 126) в io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.intercept (InterceptorOfASingleElement 59) .jj_jj_10_1029 в java .IOSElement $$ EnhancerByCGLIB $$ d311658.isDisplayed () в at ✽. И проверьте, что список бокового меню перемещается к соответствующему экрану с пользователем OnBoared (: 12). Вызвано: org.openqa.selenium.TimeoutException: ожидаемое условие не выполнено : ожидание io.appium.java_client.pagefactory. * 1 019 * (пробовали в течение 1 секунды с интервалом 500 миллисекунд) в org.openqa.selenium.support.ui.FluentWait.timeoutException (FluentWait. java: 304) в org.openqa.selenium.support.ui.FluentWait .until (FluentWait. java: 272) в io.appium.java_client.pagefactory.AppiumElementLocator.waitFor (AppiumElementLocator. java: 99) в io.appium.java_client.pagefactory.Appium *lementLocator.find.ElementLocator.find : 119) в io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.intercept (InterceptorOfASingleElement. java: 59) в io.appium.java_client. ios .IOSElement $$ EnhancerByCGLed11 at at3DisDis at at3DisDis at at3 (d) $ d$$$ sun.reflect.NativeMethodAccessorImpl.invoke0 (нативный метод) в sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl. java: 62) в sun.reflect.DelegatingMethodAccessorImpl.et0. 433. lang.reflect.Method.invoke (Method. java: 498) в cucumber.runtime.Utils $ 1.call (Utils. java: 40) в cucumber.runtime.Time out.timeout (Timeout. java: 16) в cucumber.runtime.Utils.invoke (Utils. java: 34) в cucumber.runtime. java .JavaStepDefinition.execute (JavaStepDefinition. java: 38) в cucumber.runtime.StepDefinitionMatch.runStep (StepDefinitionMatch. java: 37) в cucumber.runtime.Runtime.runStep (время выполнения. java: 300) в cucumber.runtime.model.StepContainer.runStep. StepContain47 : 44) в cucumber.runtime.model.StepContainer.runSteps (StepContainer. java: 39) в cucumber.runtime.model.CucumberScenario.run (CucumberScenario. java: 44) в cucumber.runtime.junit.ExecutionUnit. выполнить (ExecutionUnitRunner. java: 102) в cucumber.runtime.junit.FeatureRunner.runChild (FeatureRunner. java: 63) в cucumber.runtime.junit.FeatureRunner.runChild (FeatureRunner. java: 18) в или .junit.runners. . java: 288) в org.junit.runners.ParentRunner.access $ 00 0 (ParentRunner. java: 58) в org.junit.runners.ParentRunner $ 2.evaluate (ParentRunner. java: 268) в org.junit.runners.ParentRunner.run (ParentRunner. java: 363) в cucumber.runtime.junit.FeatureRunner.run (FeatureRunner. java: 70) в cucumber.api.junit.Cucumber.runChild (Cucumber. java: 95) в cucumber.api.junit.Cucumber.runChild (Огурец. java: 38) в org.junit.runners.ParentRunner $ 3.run (ParentRunner. java: 290) в org.junit.runners.ParentRunner $ 1.schedule (ParentRunner. java: 71) в org.junit .runners. 1066 *: 268) в org.junit.internal.runners.statements.RunBefores.evaluate (RunBefores. java: 26) в org.junit.internal. runners.statements.RunAfters.evaluate (RunAfters. java: 27) в org.junit.runners.ParentRunner.run (ParentRunner. java: 363) в cucumber.api.junit.Cucumber.run (огурец. java: 100) в org.junit.runner.JUnitCore.run (JUnitCore. java: 137) в org.junit.runner.JUnitCore.run (JUnitCore. java: 115) в org.junit.vintage.engine .execution.RunnerExecutor.execute (RunnerExecutor. java: 39) в java .util.stream.ForEachOps $ ForEachOp $ OfRef.accept (ForEachOps. java: 184) в java .util.stream.ReferencePipeline. $ 3 $ 1.accept (ReferencePipeline. java: 193) в java .util.Iterator.forEachRemaining (Iterator. java: 116) в java .util.Spliterators $ IteratorSpliterator.forEachRemaining (Spliterators. java : 1801) в java .util.stream.AbstractPipeline.copyInto (AbstractPipeline. java: 481) в java .util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline. java: 471) в java. util.stream.ForEachOps $ ForEachOp.evaluateSequential (ForEachOps. java: 151) в java .util.stream.ForEachOps $ ForEachOp $ OfRef.evaluateSequent ial (ForEachOps. java: 174) в java .util.stream.AbstractPipeline.evaluate (AbstractPipeline. java: 234) в java .util.stream.ReferencePipeline.forEach (ReferencePipeline. java: 418) в org.junit.vintage.engine.VintageTestEngine.executeAllChildren (VintageTestEngine. java: 79) в org.junit.vintage.engine.VintageTestEngine.execute (VintageTestEngine. java: 70) в org.junit. .launcher.core.DefaultLauncher.execute (DefaultLauncher. java: 220) в org.junit.platform.launcher.core.DefaultLauncher.lambda $ execute $ 6 (DefaultLauncher. java: 188) в org.junit.platform. launcher.core.DefaultLauncher.withInterceptedStreams (DefaultLauncher. java: 202) в org.junit.platform.launcher.core.DefaultLauncher.execute (DefaultLauncher. java: 181) в org.junit.platore.laher. DefaultLauncher.execute (DefaultLauncher. java: 128) в org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run (JUnit5TestReference. java: 89) в org.eclipse.jdt.inrun.junit. TestExecution.run (TestExecution java.: 41) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner. java: 541) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests: Remote. 763) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner. java: 463) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner: *. 209) Вызвано: org.openqa.selenium.NoSuchElementException: Невозможно найти элемент, используя By.chained ({By.AccessibilityId: OK}). Для документации по этой ошибке, пожалуйста, посетите: https://www.seleniumhq.org/exceptions/no_such_element.html Информация о сборке : версия: '3.141.59', ревизия: 'e82be7d358', время: '2018-11-14T08: 17: 03' Системная информация: хост: 'Elites-MacBook-Pro-4.local', ip: 'fe80: 0: 0: 0: 1c56: 6e8a: fceb: a653% en0 ', os.name:' Ma c OS X ', os.arch:' x86_64 ', os.version: '10 .15.3', java .version: '1.8.0_201' Информация о драйвере: driver.version: IOSDriver на io.appium.java_client.pagefactory.bys.builder.ByChained.findElement (ByChained. java: 74) на org.openqa.selenium.remote .RemoteWebDriver.findElement (RemoteWebDriver. java: 315) по адресу io.appium.java_client.DefaultGenericMobileDriver.findElement (DefaultGenericMobileDriver. java: 57) по адресу io.appium.java_client. 11Driver.Appium ) в io.appium.java_client. ios .IOSDriver.findElement (IOSDriver. java: 1) в io.appium.java_client.pagefactory.bys.ContentMappedBy.findElement (ContentMappedBy. java: 50) в орг. openqa.selenium.remote.RemoteWebDriver.findElement (RemoteWebDriver. java: 315) в io.appium.java_client.DefaultGenericMobileDriver.findElement (DefaultGenericMobileDriver. java: 57) в io.pp.jpg.jpg. java: 1) в io.appium.java_client. ios .IOSDriver.findElement (IOSDriver. java: 1) в io.appium.java_client.pagefactory.AppiumElementLocator.lambda $ 0 (AppiumElementLocator. * 11: 21 * ) по адресу io.appium.java_client.pagefactory.AppiumElementLocator $ WaitingFunction.apply (AppiumElementLocator. java: 172) по адресу io.appium.java_client.pagefactory.AppiumElementLocator $ WaitingFunction *apply (AppiumEleql). .selenium.support.ui.FluentWait.until (FluentWait. java: 249) ... еще 67

Ответы [ 3 ]

0 голосов
/ 14 февраля 2020

Вы можете написать функцию custom для мобильных элементов visibility.

public boolean checkMobileElementExist(By by)  {
        boolean objectExist = false;
        try {
            objectExist = element.findElement(by).isDisplayed();

        } catch (NoSuchElementException e) {
            return false;
        }

        return objectExist;
    }

Теперь вы можете использовать эту функцию в своем коде

if (checkMobileElementExist(By.id(id))) {
}
0 голосов
/ 15 февраля 2020

Вы можете создать собственный метод isDisplayed с некоторым явным ожиданием. Примерно так:

protected boolean isDisplayed(WebElement id, long timeOutInSeconds) {
        try {
            WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), timeOutInSeconds);
            wait.until(ExpectedConditions.visibilityOf(id));
        } catch (TimeoutException | NoSuchElementException ex) {
            return false;
        }
        return true;
    }

А затем применить к вашему элементу вот так:

if (!isDisplayed(ELEMENTNAME, 10)) {
            Assert.fail("");
        } else {
            Log.info("");
        }
    }
0 голосов
/ 14 февраля 2020

Если вы пытаетесь проверить, отображается ли элемент на странице, вы можете попробовать это:

List<WebElement> ele = driver.findElements(By.id(id));

Это вернет список элементов, соответствующих указанному вами идентификатору. Если размер списка больше 0, это означает, что элемент присутствует на странице.

...