如何使用appium从混合应用程序的下拉列表中选择值? [英] How do i select value from dropdown of a hybrid app using 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());
}
我想从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.
- 从您的对象属性看来,您现在处于本机上下文中.因此,在选择下拉菜单之前,请更改为Web Context.
driver.Context = "WebContext";
或
driver.Context = "CHROMIUM";
您的网络上下文名称可以不同 2.现在,就像使用Selenium Webdriver在Web中所做的一样选择元素
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");
Select dropdown = new Select(driver.findElement(By.id("mySelect")));
dropdown.selectByVisibleText("Text");
- 现在,您可以根据需要切换回混合应用程序的本机上下文.
注意:要查找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屋!