如何使用 appium 从混合应用程序的下拉列表中选择值? [英] How do i select value from dropdown of a hybrid app using appium?

查看:56
本文介绍了如何使用 appium 从混合应用程序的下拉列表中选择值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 appium 比较陌生,并且积极参与了 poc.要求是从下拉列表中选择一个值,但是我可以单击微调元素,但下面的任何内容都无法识别我的 uiautomator.因此,我无法从微调元素中选择任何值.我附上了脚本的代码块和元素树快照.

I am relatively new to appium, and is actively involved in a poc. The requirement is to select a value from the drop down, however i am able to click the spinner element but anything below that is not getting recognized my uiautomator. as a result i am not able to select any values from the spinner element. I am attaching the code block of the script and also the element tree snapshot.

 //trying to click the dropdown list
		 try{
			 WebElement parentElement1 = driver.findElement(By.id("retProdOp0"));
			 WebElement childElement1 = parentElement1.findElement(By
					.xpath("//android.view.View[@index='1']"));
			childElement1.click();
			driver.label("dropdown list 2nd element clicked");
		 }catch(Exception e){
			driver.label("Failed to click dropdown list on prodexchg screen");
			System.out.println(e.getMessage());
		 }
		 

快照1

Snapshot2

我想从 Snapshot2 中微调器的下拉列表中选择值.但是我无法在 uiautomator 中找到它们.寻求帮助.提前致谢.

I want to select the values from the drop down of the spinner in Snapshot2. However i am not able to locate them in uiautomator. Looking for some help. Thanks in advance.

推荐答案

以下解决方案将对您有所帮助.如果没有,请告诉我.

The below solution will help you. Let me know if it doesn't.

  1. 从您的对象属性来看,您现在似乎处于本机上下文中.因此,在选择下拉项之前,请更改为 Web Context.

driver.Context = "WebContext"; 或者

driver.Context = "CHROMIUM";

您的 webcontext 的名称可以不同2. 现在像在 w​​eb 中使用 selenium webdriver 一样选择元素

The name of your webcontext can be different 2. Now select the element just as you would do in web using selenium webdriver

Select dropdown = new Select(driver.findElement(By.id("mySelect")));dropdown.selectByVisibleText("Text");

  1. 现在,您可以根据需要切换回混合应用程序的本机上下文.

注意:要查找 webcontext 的属性,您可以获取源代码或在浏览器中访问 Web URL.

Note: To find the properties of webcontext you can fetch the source code or go to the web URL in your browser.

这篇关于如何使用 appium 从混合应用程序的下拉列表中选择值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆