cancel
Showing results for 
Search instead for 
Did you mean: 

New to QuerySelector actions .. selecting an item from a <select> tag

SOLVED
Super Contributor

New to QuerySelector actions .. selecting an item from a <select> tag

Consider this monstrosity:

 

function DateFromPicker()
{
  var month = "Apr";
  var year = "2020";
    
  var cssSelector = "#ui-datepicker-div > div > div > select.ui-datepicker-month";
  var selMonth = Aliases.browser.pageMain.panDatePicker.QuerySelector(cssSelector);
  selMonth.Click();
  ClickMonthOnPicker(selMonth, month);
    
  cssSelector = "#ui-datepicker-div > div > div > select.ui-datepicker-year";
  
      
  
}

// this just holds the long (ugly) switch case so the calling method is not so long
function ClickMonthOnPicker(selMonth, month)
{
  switch (month)
  {
    case "Jan":
      selMonth.selectedIndex = 0;
      break;
    case "Feb":
      selMonth.selectedIndex = 1;
      break;
    case "Mar":
      selMonth.selectedIndex = 2;
      break;
    case "Apr":
      selMonth.selectedIndex = 3;
      break;
    case "May":
      selMonth.selectedIndex = 4;
      break;
    case "Jun":
      selMonth.selectedIndex = 5;
      break;
    case "Jul":
      selMonth.selectedIndex = 6;
      break;
    case "Aug":
      selMonth.selectedIndex = 7;
      break;
    case "Sep":
      selMonth.selectedIndex = 8;
      break;
    case "Oct":
      selMonth.selectedIndex = 9;
      break;
    case "Nov":
      selMonth.selectedIndex = 10;
      break;
    case "Dec":
      selMonth.selectedIndex = 11;
      break;

    default:
      Log.Error("Error in test. Valid month string needed for date picker.");
      break;
  }
}

Is there something besides selectedIndex ... a relative that would allow me to select by the container text? For example select

 

<option value="0">Jan</option>

 

By "Jan"? I am still looking at what kind of "thing" selMonth is. Thanks for your patience.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: New to QuerySelector actions .. selecting an item from a <select> tag

Hi,

 

Do you need to control date picker popup or just enter some date into the field and proceed?

If the latter and value enter via .Keys() method call does not work, the following worked for me in (almost?) all cases:

-- Assign required date using correct format to the field via either direct assignment to the .Value/wText/etc. property or via the .SetText() call. Investigate what will work in your case;

-- Open date picker window. If you are lucky, it will be opened automatically after you either assign the value to the property or perform .SetFocus()/.Focus() call. If not, try to use either some key press (Down Arrow, for example) or click on the 'calendar' icon. The key point here is that date picker popup should be opened with correct date already selected;

-- Confirm date selection by pressing Enter key. Quite often it works even if you do dateField.Keys('[Enter]') without the necessity of something like datePickerPopup.Keys('[Enter]').

 

Does this help?

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

Re: New to QuerySelector actions .. selecting an item from a <select> tag

Hi,

 

Do you need to control date picker popup or just enter some date into the field and proceed?

If the latter and value enter via .Keys() method call does not work, the following worked for me in (almost?) all cases:

-- Assign required date using correct format to the field via either direct assignment to the .Value/wText/etc. property or via the .SetText() call. Investigate what will work in your case;

-- Open date picker window. If you are lucky, it will be opened automatically after you either assign the value to the property or perform .SetFocus()/.Focus() call. If not, try to use either some key press (Down Arrow, for example) or click on the 'calendar' icon. The key point here is that date picker popup should be opened with correct date already selected;

-- Confirm date selection by pressing Enter key. Quite often it works even if you do dateField.Keys('[Enter]') without the necessity of something like datePickerPopup.Keys('[Enter]').

 

Does this help?

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

Community Manager

Re: New to QuerySelector actions .. selecting an item from a <select> tag

Thanks for the suggestion, Alex.

@vthomeschoolmom, does it work for your test?

 

 

---------
Tanya Gorbunova
SmartBear Community Manager

Join the annual community event and share your stories to win gifts
Wintertainment2019