问题描述
限时送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:关键词]
发布评论