Ruby Selenium unable to select image from android image gallery

风格不统一 提交于 2019-12-08 04:03:50

问题


I am trying to select an image from Android image galley grid view. This grid view has ImageView for every image. Every ImageView has id.

So when i am trying to get by //ImageView[@id="someId"][1] or by //GridView[@id="someId"]//ImageView[@id="someId"][1], it does not find it.

How can I select image from gallery using Selenium webdriver in ruby.

EDIT:

<GridView id = "someId">
    <LinearView>
        <ImageView id = "someImageId"></ImageView>
    </LinearView>
    <LinearView>
        <ImageView id = "someImageId"></ImageView>
    </LinearView>
    <LinearView>
        <ImageView id = "someImageId"></ImageView>
    </LinearView>
    <LinearView>
        <ImageView id = "someImageId"></ImageView>
    </LinearView>
</GridView>

EDIT As Uiautomator cannot select the thumbnails in Gallery, I tried to pick image using relative co ordinates but this is giving an error.

Is any one has done this? I need to select image from android gallery.


回答1:


If you want the first image (ImageView) :

//*[@id='someId']/LinearView[1]/ImageView

Output :

<ImageView id="someImageId"/>

You can change the index in the LienarView array selection.

element = driver.find_element(:xpath, "//*[@id='someId']/LinearView[1]/ImageView")
p element
# <Selenium::WebDriver::Element:0x3eb6a9d8 id="{ea847fbe-7fc7-453b-97ea-74fbf325ddac}">

edit : You can also fetch all elements using find_elements() into an array and then, juste select the one you want :

elements = driver.find_elements(:xpath, '//ImageView')
p elements[1]
# <Selenium::WebDriver::Element:0x..f9bdc4412 id="{1f41fbd9-0a73-4fb2-9c98-44bb877e2388}">



回答2:


You should be able to find it with Appium using:

//android.widget.ImageView[@id="someId"][1] 

or

//android.widget.GridView[@id="someId"]//android.widget.ImageView[@id="someId"][1]


来源:https://stackoverflow.com/questions/23909548/ruby-selenium-unable-to-select-image-from-android-image-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!