Ruby Selenium 无法从 android 图像库中选择图像 [英] Ruby Selenium unable to select image from android image gallery
问题描述
我正在尝试从 Android 图像厨房网格视图中选择图像.这个网格视图对每个图像都有 ImageView
.每个 ImageView
都有 id.
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.
所以当我试图通过 //ImageView[@id="someId"][1]
或通过 //GridView[@id="someId"]//ImageView[@id="someId"][1]
,它没有找到.
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.
如何使用 Selenium webdriver in ruby
从图库中选择图像.
How can I select image from gallery using Selenium webdriver in ruby
.
<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>
编辑由于 Uiautomator 无法在图库中选择缩略图,我尝试使用相对坐标选择图像,但这是错误的.
EDIT As Uiautomator cannot select the thumbnails in Gallery, I tried to pick image using relative co ordinates but this is giving an error.
有人做过吗?我需要从 android 库中选择图像.
Is any one has done this? I need to select image from android gallery.
推荐答案
如果你想要第一张图片 (ImageView
) :
If you want the first image (ImageView
) :
//*[@id='someId']/LinearView[1]/ImageView
输出:
<ImageView id="someImageId"/>
您可以在 LienarView
数组选择中更改索引.
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}">
您还可以使用 find_elements()
将所有元素提取到一个数组中,然后选择您想要的元素:
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}">
这篇关于Ruby Selenium 无法从 android 图像库中选择图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!