我在一个网页中有一个下拉列表,如下所示
在我的android应用程序中,我有一个网页视图,其中显示了这个网页。我正在尝试设置一个espresso测试,我可以点击下拉列表,然后选择,比方说,第四个选项,本地用户。
在下拉列表下面有一个"continue“按钮,我有一个代码
onWebView()
.withElement(findElement(Locator.ID, "continueButton"))
.perform(webClick());
单击该按钮,但在此之前,我需要能够选择下拉列表并更改选定的选项。问题是我如何做到这一点。
我试过了
onWebView()
.withElement(findElement(Locator.ID, "userStoreDomain"))
.perform(webClick());
但是,它甚至不会单击下拉列表来打开它。选择一个选项大相径庭。有没有人知道espresso webview有没有可能?
发布于 2016-01-20 09:11:38
我想我找到了一个解决方案。
这就是对我有效的解决方案:
onWebView()
//I use this to allow all needed time to WebView to load
.withNoTimeout()
// Find the select element by ID
.withElement(findElement(Locator.ID, "EXPDT_YY"))
.perform(webClick());
onWebView()
//I use this to allow all needed time to WebView to load
.withNoTimeout()
// I select the element with xpath because I'm using a WebView which I can't control
//and the <option> elements have only the value attribute
// I think it should work with any proper Locator (name, id etc..)
.withElement(findElement(Locator.XPATH, "//option[@value='20']"))
.perform(webClick());
https://stackoverflow.com/questions/34323701
复制