【问题标题】:Is there a way to get all the elements with the same class type有没有办法获得具有相同类类型的所有元素
【发布时间】:2020-02-23 08:06:09
【问题描述】:

使用Appium python客户端,我想获取所有返回的视图;

elements = driver.find_elements_by_class_name(‘foo’) 在容器中;喜欢列表或其他。

我可以试试

elements = driver.find_elements_by_class_name(‘foo’)
for i in len(elements)
   list_element + i = elements

那么我可以使用 list_element 访问所有属于该类的元素列表吗?

【问题讨论】:

  • 谢谢,@frianH,我已经做了类似的事情,``` # Test EditText Class user_action = TouchAction(driver) element_class= driver.find_elements_by_class_name("android.widget.EditText") element_class[0] .click() driver.set_value(element_class[0], "Goodies") # 在新屏幕上向下滑动 driver.execute_script('mobile: performEditorAction', {'action': 'done'}) ``` 所以有没有print (elements[i]) 并获取每个索引中元素的名称?此外,向下滑动的代码不起作用。我试着在打电话之前延迟..仍然没有,有什么建议吗?

标签: appium appium-android python-appium


【解决方案1】:

是的,你可以做到。假设你想点击:

elements = driver.find_elements_by_class_name('foo')
for element in elements:
    element.click()

或者如果你想访问elements中的特定元素,你可以使用索引:

elements = driver.find_elements_by_class_name('foo')
#first element
elements[0].click()

【讨论】:

    【解决方案2】:

    谢谢@frianH,我已经做过类似的事情了,

    # Test EditText Class
    user_action = TouchAction(driver)
    element_class = driver.find_elements_by_class_name("android.widget.EditText")
    
    element_class[0].click()
    driver.set_value(element_class[0], "Goodies")
    
    # swipe down on new screen
    user_action.driver.execute_script('mobile: performEditorAction', {'action': 'done'})
    

    那么有没有办法print (elements[i]) 那就是获取元素的名称?

    此外,向下滑动的代码也不起作用。我试着在打电话之前推迟一下。。还是没有,有什么建议吗?

    【讨论】:

    • 请创建另一个问题,然后发布。不像这样的答案。
    • 哦,好的。我试图对您的答案发表评论,但代码格式是错误的。我花了一些宝贵的时间。
    猜你喜欢
    • 2021-06-19
    • 2022-01-23
    • 1970-01-01
    • 2012-08-15
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    相关资源
    最近更新 更多