New to QuerySelector actions .. selecting an item from a <select> tag
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
/Alex [Community Hero]
____
[Community Heroes] 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. Posts made by [Community Heroes]
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.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the suggestion, Alex.
@vthomeschoolmom, does it work for your test?
Tanya Yatskovskaya
SmartBear Community and Education Manager
