求助 appcrawler 怎么选择listView的第二项

<android.widget.FrameLayout>

<android.widget.FrameLayout>

<android.widget.ListView>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

<android.widget.CheckedTextView resource-id=“android:id/text1”>

第2项的文本是YELLOW
利用trigger action

  • { xpath: “//*[contains(@text, ‘YELLOW’)]”, action: click, times: 1 }
    实际选到的是第一项

实际点击的元素 取的第一项
[AppiumClient.190.findElements] findElementsByXPath //android.widget.FrameLayout[@class=‘android.widget.FrameLayout’]//android.widget.FrameLayout[@class=‘android.widget.FrameLayout’]//android.widget.ListView[@class=‘android.widget.ListView’]//android.widget.CheckedTextView[@resource-id=‘android:id/text1’ and @class=‘android.widget.CheckedTextView’]

xpath中有这种用法 //x…[2]

下拉列表的内容会变,比如里面内容多了,不一定在第二项,这样hardcode 可能不准确

试了一下这种hardcode也不好使
(//[contains(@resource-id, ‘android:id/text1’)])[2] 也还是选中的第一项
//
[contains(@text, ‘YELLOW’)] 这种也是

最要的是发现的元素还是原来的那个
2022-03-08 10:06:50 INFO [AppiumClient.190.findElements] findElementsByXPath //android.widget.FrameLayout[@class=‘android.widget.FrameLayout’]//android.widget.FrameLayout[@class=‘android.widget.FrameLayout’]//android.widget.ListView[@class=‘android.widget.ListView’]//android.widget.CheckedTextView**[@resource-id=‘android:id/text1’ and @class=‘android.widget.CheckedTextView’]**

可能跟xpath的生成方式有关系,你贴下配置,估计需要修改下配置才能实现,貌似默认配置不太支持这种情况,需要修改xpath attributes

selectedList:
- xpath: “//[contains(@resource-id, ‘recycleview’)]//[contains(@resource-id, ‘myItemName’) and contains(@class, ‘Text’)]”
- xpath: “//[contains(@resource-id, ‘container_btns2’)]//[contains(@class, ‘Text’) and @text!=’’]”
- xpath: “//[@clickable=‘true’]//[contains(@class, ‘Text’)]”
- xpath: “//[contains(@class, ‘Image’)]"
- xpath: "//
[contains(@class, ‘Button’)]”
- xpath: “//[contains(@class, ‘Switch’)]"
- xpath: "//
[contains(@class, ‘Spinner’)]”
triggerActions:
# login
- { xpath: “//[contains(@resource-id, ‘image_close’)]", action: driver.click();Thread.sleep(3000) }
- { xpath: "//
[contains(@resource-id, ‘drawer_icon’)]”, action: click, times: 1 }
- { xpath: “//[contains(@resource-id, ‘menu_login_layout’)]", action: click, times: 1 }
- { xpath: "//
[contains(@resource-id, ‘edtEmail_login’)]”, action: “phototest123@avqtest.test”, times: 1 }
- { xpath: “//[contains(@resource-id, ‘edtPassword_login’)]", action: “test4321”, times: 1 }
- { xpath: "//
[contains(@resource-id, ‘btnSignIn’)]”, action: driver.click();Thread.sleep(10000), times: 1 }
- { xpath: “//*[contains(@resource-id, ‘image_close’)]”, action: driver.click();Thread.sleep(3000) }

# set color
- { xpath: "//*[contains(@resource-id, 'drawer_icon')]", action: click, times: 1 }
- { xpath: "//*[contains(@resource-id, 'nav_view')]", action: "driver.swipe(0.5, 0.7, 0.5, 0.3);Thread.sleep(2000)", times: 1 }
- { xpath: "//*[contains(@resource-id, 'sliding_menu_settings')]", action: click, times: 1 }
- { xpath: "//*[contains(@resource-id, 'about_list')]", action: "driver.swipe(0.5, 0.7, 0.5, 0.3);Thread.sleep(2000)", times: 1 }
- { xpath: "//*[contains(@resource-id, 'setting_country_spinner')]", action: click, times: 1 }
- { xpath: "//*[contains(@resource-id, 'android:id/text1') and @text='Yellow']", action: click, times: 1 }
- { xpath: "//*[contains(@text, 'DONE')]", action: click, times: 1 }

- { xpath: "//*[contains(@resource-id, 'begin_button')]", action: click, times: 1 }
- { xpath: "//*[contains(@text, 'allow') or @text='Allow']", action: click, times: 5 }
- { xpath: "//*[contains(@resource-id, 'begin_button')]", action: click, times: 1 }
- { xpath: "//*[contains(@resource-id, 'albumTitle') and @text='Camera']", action: click, times: 1 }
- { xpath: "//*[contains(@resource-id, 'image_close')]", action: click }
- { xpath: "//*[contains(@resource-id, 'android:id/button1') and @text='Close']", action: click }
- { xpath: "//*[contains(@resource-id, 'edtCreditCartNumber')]", action: 44332211, times: 1 }
- { xpath: "//*[contains(@resource-id, 'payment_cvv_edt')]", action: 123, times: 1 }
- { xpath: "//*[contains(@resource-id, 'txt_nothanks')]", action: click, times: 2 }

blackList:
- given:
when: null
then:
xpath: “//[contains(@resource-id, ‘button_menu_delete’)]" # photo tile delete
action: “”
actions: [ ]
times: -1
- xpath: "//
[contains(@resource-id, ‘drawer_layout’)]//" # all items in get started page
- xpath: "//
[contains(@resource-id, ‘sourceTabLayout’)]//" # all photo source
- xpath: "//
[contains(@resource-id, ‘selectphoto_root_view’)]//[not(contains(@resource-id, ‘select_status’))]" # all photo folders
- xpath: "//
[contains(@resource-id, ‘ConstraintLayout_AppZone’)]//"
- xpath: "//
[contains(@resource-id, ‘editor_save_button’)]//"
- xpath: “Cancel”
firstList:
- xpath: "//
[contains(@resource-id, ‘txt_nothanks’)]”
- xpath: “//[contains(@text, ‘No Thanks’) or contains(@text, ‘No thanks’) or contains(@text, ‘NO THANKS’)]"
lastList:
- xpath: "//
[@selected=‘true’]/…//"
- xpath: "//
[@selected=‘true’]/…/…//"
- xpath: "//
[contains(@resource-id, ‘selected’)]”
- xpath: “//[contains(@resource-id, ‘select_status’)]"
- xpath: "//
[contains(@resource-id, ‘btn_ship’)]//"
- xpath: "//
[contains(@resource-id, ‘btnContinue’)]//"
- xpath: “NEXT”
- { xpath: "//
[contains(@resource-id, ‘btnCreditCardPaytv’)]/parent::android.widget.LinearLayout//", action: driver.click();Thread.sleep(8000)} # order summary submit order
- { xpath: "//
[contains(@resource-id, ‘TXT_SUBMIT’)]/parent:://”, action: driver.click();Thread.sleep(8000)}
- xpath: “//[contains(@resource-id, ‘navigate_home’)]//
- xpath: “CHECKOUT”
- xpath: “//*[@text=‘done’ or @text=‘DONE’]”
backButton:
- given:
when: null
then:
xpath: “Navigate up”
action: “”
actions:
times: -1

思寒 有解决办法吗,好多处遇到这种情况了

最后点击的xpath中感觉没有加入@text=‘YELLOW’

如果是组成这种表达式应该可以点击

//android.widget.FrameLayout[@class=‘android.widget.FrameLayout’]//android.widget.FrameLayout[@class=‘android.widget.FrameLayout’]//android.widget.ListView[@class=‘android.widget.ListView’]//android.widget.CheckedTextView**[@resource-id=‘android:id/text1’ and @class=‘android.widget.CheckedTextView’ and @text=‘YELLOW’]**