NoSuchElementException: элемент не может быть расположен на странице, используя заданные параметры поиска - PullRequest
1 голос
/ 09 апреля 2019

Код, который я использую:

public class SafariTest {
private static IOSDriver iOSDriver;
private WebElement loginSettingsButton;
@Before
public void preTest() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "xxxx");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.1");

    capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
    capabilities.setCapability(MobileCapabilityType.UDID, "xxxx");
    capabilities.setCapability(MobileCapabilityType.APP,"/xxx.app");

    iOSDriver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    //webDriver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCase(){
    WebDriverWait wait = new WebDriverWait(iOSDriver, 15); 
loginSettingsButton = iOSDriver.findElement(By.name("loginSettingsButton"));
loginSettingsButton.click();
}

@After
public void finishTest(){
    //  webDriver.quit();
}

public static void setContextToWebview(){
    Set<String> availableContexts = iOSDriver.getContextHandles();
    availableContexts.stream()
            .filter(context -> context.toLowerCase().contains("webview"))
            .forEach(newcontext -> iOSDriver.context(newcontext));
}

}

Ошибка, которую я получил:

org.openqa.selenium.NoSuchElementException: элемент не может быть расположен на странице с использованием заданных параметров поиска. Для документации по этой ошибке, пожалуйста, посетите: https://www.seleniumhq.org/exceptions/no_such_element.html Информация о сборке: версия: '3.141.59', редакция: 'e82be7d358', время: '2018-11-14T08: 17: 03' Системная информация: хост: 'xxxx.local', ip: 'xxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10 .14.4 ', java.version:' 1.8.0_152-релиз» Информация о драйвере: io.appium.java_client.ios.IOSDriver Возможности {приложение: xxx, имя_автоматизации: XCUITest, имя_браузера:, databaseEnabled: false, имя_устройства: xxxx, javascriptEnabled: истина, locationContextEnabled: ложь, networkConnectionEnabled: ложь, платформа: MAC, имя_платформы: iOS, platformVersion: 12.1, снимок экрана: true : xxxx ..., webStorageEnabled: false} Идентификатор сеанса: a2b7627f-9792-4df3-874b-96ced13fc185 *** Информация об элементе: {Using = name, value = loginSettingsButton} at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (собственный метод) at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45) в java.lang.reflect.Constructor.newInstance (Constructor.java:423) в org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException (W3CHttpResponseCodec.java:187) в org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode (W3CHttpResponseCodec.java:122) в org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode (W3CHttpResponseCodec.java:49) в org.openqa.selenium.remote.HttpCommandExecutor.execute (HttpCommandExecutor.java:158) в io.appium.java_client.remote.AppiumCommandExecutor.execute (AppiumCommandExecutor.java:239) в org.openqa.selenium.remote.RemoteWebDriver.execute (RemoteWebDriver.java:552) в io.appium.java_client.DefaultGenericMobileDriver.execute (DefaultGenericMobileDriver.java:42) в io.appium.java_client.AppiumDriver.execute (AppiumDriver.java:1) в io.appium.java_client.ios.IOSDriver.execute (IOSDriver.java:1) в org.openqa.selenium.remote.RemoteWebDriver.findElement (RemoteWebDriver.java:323) в io.appium.java_client.DefaultGenericMobileDriver.findElement (DefaultGenericMobileDriver.java:62) в io.appium.java_client.AppiumDriver.findElement (AppiumDriver.java:1) в io.appium.java_client.ios.IOSDriver.findElement (IOSDriver.java:1) в org.openqa.selenium.remote.RemoteWebDriver.findElementByName (RemoteWebDriver.java:404) в io.appium.java_client.DefaultGenericMobileDriver.findElementByName (DefaultGenericMobileDriver.java:118) в io.appium.java_client.AppiumDriver.findElementByName (AppiumDriver.java:1) в io.appium.java_client.ios.IOSDriver.findElementByName (IOSDriver.java:1) в org.openqa.selenium.By $ ByName.findElement (By.java:284) в org.openqa.selenium.remote.RemoteWebDriver.findElement (RemoteWebDriver.java:315) в io.appium.java_client.DefaultGenericMobileDriver.findElement (DefaultGenericMobileDriver.java:58) в io.appium.java_client.AppiumDriver.findElement (AppiumDriver.java:1) в io.appium.java_client.ios.IOSDriver.findElement (IOSDriver.java:1) в com.example.appiumapplication.SafariTest.testCase (SafariTest.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) в java.lang.reflect.Method.invoke (Method.java:498) в org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall (FrameworkMethod.java:50) в org.junit.internal.runners.model.ReflectiveCallable.run (ReflectiveCallable.java:12)в org.junit.runners.model.FrameworkMethod.invokeExplosively (FrameworkMethod.java:47) в org.junit.internal.runners.statements.InvokeMethod.evaluate (InvokeMethod.java:17) в org.junit.internal.runners.statements.RunBefores.evaluate (RunBefores.java:26) в org.junit.internal.runners.statements.RunAfters.evaluate (RunAfters.java:27) в org.junit.runners.ParentRunner.runLeaf (ParentRunner.java:325) в org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:78) в org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:57) в org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:290) в org.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:71) в org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288) в org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:58) в org.junit.runners.ParentRunner $ 2.evaluate (ParentRunner.java:268) в org.junit.runners.ParentRunner.run (ParentRunner.java:363) в org.junit.runner.JUnitCore.run (JUnitCore.java:137) в com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs (JUnit4IdeaTestRunner.java:68) в com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs (IdeaTestRunner.java:47) в com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart (JUnitStarter.java:242) в com.intellij.rt.execution.junit.JUnitStarter.main (JUnitStarter.java:70) Процесс завершен с кодом выхода 255

1 Ответ

0 голосов
/ 09 апреля 2019

Вместо использования findElement (By.Name ("...")) метод, попробуйте использовать findElementByAccessibilityId ("loginSettingsButton")

loginSettingsButton = iOSDriver.findElementByAccessibiltyId("loginSettingsButton");

убедитесь, что элемент присутствует с loginSettingsButton как automaId т.е. описание содержимого

Использование имени, xpath не рекомендуется для appium. Вы должны использовать id accessibiltyили идентификатор при использовании appium.Если у вас нет идентификатора автоматизации, такого как cont-desc, resource-id или id, вы можете попросить команду разработчиков добавить его

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...