使用selenium,appium和C#在datepicker上选择年份 [英] Select year on datepicker using selenium, appium and C#

查看:567
本文介绍了使用selenium,appium和C#在datepicker上选择年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择/点击Android应用程序的日期选择器上的隐藏元素来选择一年,因为该元素是隐藏的,我需要在单击之前移动到该元素,我尝试过各种方法,没有产生期望的结果。在日期选择器上,默认选择的是今年(2017年),如果我选择上一年(2016),它可以正常工作。
如何选择像1992年这样的一年,因为在点击之前我需要刷新它?



代码:

  _driver.FindElement(By.Id(com.appzonegroup.dejavuandroid.zoneRevamp:id / dob))。 

int ThisYear = Int32.Parse(_driver.FindElement(By.Id(com.appzonegroup.dejavuandroid.zoneRevamp:id / date_picker_year))。
String RegistrableYear = Convert.ToString(ThisYear - 25);
_driver.FindElement(By.Id(com.appzonegroup.dejavuandroid.zoneRevamp:id / date_picker_year))。

IWebElement ElementToClick = _driver.FindElement(By.XPath(// android.widget.TextView [@ text =+'+ RegistrableYear +'+]));
Actions ActionBuilder = new Actions(_driver);
动作HoverAction = ActionBuilder.MoveToElement(ElementToClick).MoveByOffset(GetX(10),GetY(10))。
HoverAction.Build()。Perform();




错误日志

 > info:[debug]将命令推送到app工作队列:[find,{strategy:xpath,selector:// android.widget.TextView [@ text ='1992'],context :,multiple:false}] 
>信息:[debug] [BOOTSTRAP] [debug]从客户端获取数据:{cmd:action,action:find,params:{strategy:xpath,selector //android.widget.TextView[@text='1992']\",\"context\":\"\",\"multiple\":false}}
> info:[debug] [BOOTSTRAP] [debug]命令类型为ACTION
> info:[debug] [BOOTSTRAP] [debug]得到命令动作:find
> info:[debug] [BOOTSTRAP] [debug]查找//android.widget.TextView[@text='1992']使用XPATH与contextId:multiple:false
> info:[debug] [BOOTSTRAP] [debug]返回结果:{status:7,value:找不到使用提供的策略的元素}
> info:[debug] 20354ms后条件未满。超时
> info:[debug]响应客户端错误:{status:7,value:{message:使用给定的搜索参数无法在页面上找到一个元素,origValue:找不到使用提供的策略的元素。},sessionId:f4ed7681-9932-42e3-9490-3cc2b556cd11}


解决方案

使用scrollto()方法,它将帮助您滚动到要选择的日期。


I am trying to select/click on a hidden element on a date picker of an android app to select a year, because the element is hidden I need to move to the element before clicking, I have tried various approaches but they've not yielded the desired result. On the date picker, the default selected is the present year (2017), if I select the previous year (2016) it works fine. How do I select a year like 1992 since I would have to swipe it to focus before clicking?

Code:

_driver.FindElement(By.Id("com.appzonegroup.dejavuandroid.zoneRevamp:id/dob")).Click();

            int ThisYear = Int32.Parse(_driver.FindElement(By.Id("com.appzonegroup.dejavuandroid.zoneRevamp:id/date_picker_year")).Text);
            String RegistrableYear = Convert.ToString(ThisYear - 25);
            _driver.FindElement(By.Id("com.appzonegroup.dejavuandroid.zoneRevamp:id/date_picker_year")).Click();

            IWebElement ElementToClick = _driver.FindElement(By.XPath("//android.widget.TextView[@text=" +"'"+RegistrableYear+"'"+"]"));
            Actions ActionBuilder = new Actions(_driver);
            Actions HoverAction = ActionBuilder.MoveToElement(ElementToClick).MoveByOffset(GetX(10), GetY(10)).Click();
            HoverAction.Build().Perform();

Error log

> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.widget.TextView[@text='1992']","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='1992']","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.widget.TextView[@text='1992'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":7,"value":"Could not find an element using supplied strategy. "}
> info: [debug] Condition unmet after 20354ms. Timing out.
> info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"Could not find an element using supplied strategy. "},"sessionId":"f4ed7681-9932-42e3-9490-3cc2b556cd11"}

解决方案

Use scrollto() method and it will help you to scroll to the date which you want to select.

这篇关于使用selenium,appium和C#在datepicker上选择年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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