【问题标题】:Exception: An element could not be located on the page using the given search parameters in Appium例外:使用 Appium 中给定的搜索参数无法在页面上找到元素
【发布时间】:2016-12-26 18:20:20
【问题描述】:

尝试在 Browserstack-cloud 中的 iPad-emulator 上自动进行测试。我尝试过的许多定位器策略都中断了以下异常:

例外:使用给定的搜索参数无法在页面上找到元素

因为我尝试了许多变体,所以我很确定我的错误是一个普遍的错误 - 但我找不到它。我的 C# 代码:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("device", "iPad Air 2");
capabilities.SetCapability("browserstack.user", browserStackUser);
capabilities.SetCapability("browserstack.key", browserStackKey);
capabilities.SetCapability("name", "ios - actions");

Uri serverUri = new Uri("http://hub.browserstack.com/wd/hub/");
AppiumDriver<IWebElement> driver = new IOSDriver<IWebElement>(serverUri, capabilities, new TimeSpan(1000000000000));
driver.Navigate().GoToUrl("http://www.amazon.de");
driver.Context = "NATIVE_APP";
Thread.Sleep(20000);
IWebElement anyElement = driver.FindElementByName("field-keywords");

这种方法的一般错误是什么?

这是我尝试定位的元素:

【问题讨论】:

    标签: appium browserstack


    【解决方案1】:

    能否请您发布屏幕截图,以便我可以给您使用的位置策略。此外,您可以使用 get API 代替 GoToUrl。下面的代码是在java中。

    driver.get(""http://www.amazon.de");
    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(BY-LOCATOR-STRATEGY-HERE)); //wait for page to load before finding any element
    WebElement element = driver.findElement(BY-LOCATOR-STRATEGY-HERE);
    

    【讨论】:

    • 我添加了一个截图。定位器策略是按名称命名的。
    • @projekt-fisch :我没有使用浏览器堆栈进行 appium 自动化。但是,因为这是浏览器,所以你的上下文不能有 NATIVE_APP。此上下文用于本机应用程序。您的测试是否会启动浏览器并打开亚马逊网站?如果是,那么您可以为亚马逊徽标添加等待声明,然后单击搜索栏。 wait.until(ExpectedConditions.presenceOfElementLocated(By.id("nav-logo"))); driver.findElement(By.id("twotabsearchtextbox")).sendKeys("TEXT-TO-SEARCH");
    • 谢谢。您的答案朝着“正常”浏览器自动化的方向发展。但我需要在 iPad 模拟器上找到该元素。
    • 相同的 wait.untilElement 和 findElement 方法可用于在 iPad 模拟器上查找元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 2017-01-15
    • 2019-06-23
    • 2019-08-30
    • 2021-09-29
    • 1970-01-01
    • 2019-08-18
    相关资源
    最近更新 更多