如何使用Android的网络驱动器,选择选择标签的任何选项 [英] How to select any option of select tag using android web driver

查看:203
本文介绍了如何使用Android的网络驱动器,选择选择标签的任何选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写测试用例针对Android设备网站。中,我需要选择从下拉页面列表中的选项。但似乎Android网络驱动程序不提供有关它的任何解决方案。

I am writing test cases for a website for android device. In which i need to select an option from the drop down list of the page. But it seems that android web driver does not provide any solution regarding it.

我试过选择API,但它不工作。

I tried the Select API but it is not working.

code段

      Select loginType = new Select(this.driver.findElement(By.xpath(LOGIN_TYPE_CHOICE)));
      loginType.selectByValue("smartphone");
      driver.findElement(By.id(LOGIN_BUTTON)).click();

寻找一些解决办法。

Looking for some workaround.

亲切问候

迪帕克·戈埃尔

推荐答案

我使用C#来运行Android的对抗Selenium测试,火狐Chrome和IE和我enounterd同样的问题与Android驱动程序。

I'm using c# to run selenium tests against android, firefox Chrome and IE and I enounterd the same problem with the android driver.

这为我工作:(它应该在J​​ava工作,如果你根据Java约定重构code)

This worked for me : (it should work in java if you refactor the code according to the Java conventions)

string jsToBeExecuted="document.getElementById('<insert dropdown Id here>').selectedIndex=<insert index here>";

IJavaScriptExecutor jsExecutor = (IJavaScriptExecutor)this.Driver;
jsExecutor.ExecuteScript(jsToBeExecuted);

注意,没有变化将在屏幕上呈现! ! !

一旦提交与所选索引的元素将被使用。
如果你想要一些调整,添加到它选择通过短信或任何你喜欢的元素它是由你。

Note that no changes will be rendered on screen ! ! !

Upon submitting the element with the selected index will be used. It is up to you if you want to add some tweaks to it to select the elements by text or whatever you like.

这篇关于如何使用Android的网络驱动器,选择选择标签的任何选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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