使用 selenium、appium 和 C# 在日期选择器上选择年份

编程入门 行业动态 更新时间:2024-10-26 16:31:09
本文介绍了使用 selenium、appium 和 C# 在日期选择器上选择年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我试图在 Android 应用程序的日期选择器上选择/单击隐藏元素以选择年份,因为该元素被隐藏我需要在单击之前移动到该元素,我尝试了各种方法,但它们没有得到想要的结果.在日期选择器上,默认选择的是今年(2017 年),如果我选择上一年(2016 年)它工作正常.我如何选择像 1992 年这样的年份,因为我必须在点击之前滑动它才能获得焦点?

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?

代码:

_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();

错误日志

> 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"}

推荐答案

使用 scrollto() 方法,它会帮助你滚动到你想要选择的日期.

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

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

更多推荐

[db:关键词]

本文发布于:2023-04-17 18:29:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/919145.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:年份   器上   日期   selenium   appium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!