【问题标题】:How to select dropdown value in Scrollview using Appium?如何使用 Appium 在 Scrollview 中选择下拉值?
【发布时间】:2020-10-05 20:08:46
【问题描述】:

我正在尝试选择一个下拉值,但下拉列表位于 android.widget.ScrollView 下,我在其中找不到任何其他定位器。

这是元素的样子

我试过下面的代码

String DESTINATION_ELEMENT_TEXT= "DE";
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().textContains(\""+DESTINATION_ELEMENT_TEXT+"\"))");

它确实执行滚动直到所有下拉值但无法选择DE作为值并最终抛出异常:

org.openqa.selenium.NoSuchElementException:一个元素不能 使用给定的搜索参数位于页面上。为了 有关此错误的文档,请访问: http://seleniumhq.org/exceptions/no_such_element.html

有人可以帮我处理滚动视图并选择所需的值吗?

【问题讨论】:

    标签: java selenium appium appium-android android-uiautomator


    【解决方案1】:

    所以我从来没有在 android 上使用过 Selenium,但问题可能是你必须等到元素生成。看看WebDriverWait

    示例代码(python)(您必须根据自己的目的对其进行修改)

    wait = WebDriverWait(browser, 2) # 2 seconds timeout
    wait.until(expected_conditions.visibility_of_element_located((By.CLASS_NAME, 'classname')))
    

    【讨论】:

    • 谢谢,但这不起作用。我尝试了所有可能的等待条件。这里的问题是元素识别而不是同步。没有什么特定的(名称、id、类)可以用来定位这些下拉值。
    猜你喜欢
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2014-09-15
    相关资源
    最近更新 更多