How to set date in Date picker on iOS?

Hi All.
I need to set date in datepicker on iOS 10.3 using Xamarin.UITest 2.0.9
Repl crashes on attempt to get the tree but I use the following query q => q.Class("UIDatePicker") for this element.
I tried to set date using the following code
app.Query(q => q.Class("UIDatePicker").Invoke("setDate", date, false)) where date is a DateTime object, but it throws the exception:

System.Exception : Error while performing Query([unknown])
----> System.Exception : Invoking an iOS selector requires either 0 or an uneven number of arguments (they have to match up pairwise including method name).

Can anybody help me with this issue?

Tagged:

Answers

  • DarshanJSDarshanJS USMember ✭✭✭

    @PavelAnihimovsky said:
    Hi All.
    I need to set date in datepicker on iOS 10.3 using Xamarin.UITest 2.0.9
    Repl crashes on attempt to get the tree but I use the following query q => q.Class("UIDatePicker") for this element.
    I tried to set date using the following code
    app.Query(q => q.Class("UIDatePicker").Invoke("setDate", date, false)) where date is a DateTime object, but it throws the exception:

    System.Exception : Error while performing Query([unknown])
    ----> System.Exception : Invoking an iOS selector requires either 0 or an uneven number of arguments (they have to match up pairwise including method name).

    Can anybody help me with this issue?

    Try this sample it may help you https://github.com/SharpMobileCode/ModalPickerViewController

    And this link http://sharpmobilecode.com/a-replacement-for-actionsheet-date-picker/
    i got these links while searching for my project

  • PavelAnihimovskyPavelAnihimovsky USMember
    edited May 26

    @DarshanJS, but I need to set date from the test without the access to app source code.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭

    Try the following. I got this elsewhere but have not yet tried.

    app.Query(x => x.Class("UIPickerView").Invoke("selectRow", date.Month - 1, "inComponent", 0, "animated", true));
    app.Query(x => x.Class("UIPickerView").Invoke("selectRow", date.Day - 1, "inComponent", 1, "animated", true));
    app.Query(x => x.Class("UIPickerView").Invoke("selectRow", date.Year - 1, "inComponent", 2, "animated", true));
    
  • NewUser.4625NewUser.4625 USMember

    Hi Pavel Anihimovsky,

    I am facing same issue. Have you find any solution

  • HubertusGrabnerHubertusGrabner USMember ✭✭

    Hi!
    I am using the following code with an invoke call:

    var timeToSet = targetDate.ToLocalTime();
    _App.Query(c => c.Class("UIDatePicker").Invoke("setDate", timeToSet));

    This sets the complete time at once.

Sign In or Register to comment.