Playwright - select random option - playwright

I want the test to filter the results randomly.
Choosing option:
selects = section.locator("select")
number_of_selects = selects.count()
chosen_number = randint(1, number_of_selects)
chosen_select = elements.nth(chosen_number - 1)
options = chosen_select.locator("option")
number_of_options = options.count()
chosen_number = randint(1, number_of_options)
chosen_option = options.nth(chosen_number - 1)
When I try to select the chosen option, I get a problem:
I've tried with text_content()...
select_name = chosen_select.text_content()
option_name = chosen_option.text_content()
page.locator(select_name).select_option(label=option_name)
...with get_attribute()...
chosen_value = chosen_option.get_attribute("value")
page.locator(select_name).select_option(chosen_value)
...but i get an error every time:
Locator.select_option(-YesNo)
waiting for selector "-YesNo"
HTML:
<selecet id="listYN">
<option value=-1>"-"</option>
<option value=YES>"Yes"</option>
<option value=NO>"No"</option>
</select>
How can I randomly select options?

after a few hours, I found the answer:
chosen_select.select_option(chosen_value)

Related

Overcome duplicate tag constraint with several SelectableSections

I am using Eureka Forms to build a survey form and have not been able to design my swift properly to overcome the error with duplicate tags.
Many of the questions need only a "Yes/No" type answer and I decided to use the ImageCheckRow selectableValue as found in the Example Project. However I can't figure out how to have two or more List Sections in the same form that re-use the "YES/NO" answer as the code below throws a
Thread 1: Assertion failed: Duplicate tag userAnswer
My code so far
form +++
let userAnswer = ["Yes", "No"]
SelectableSection<ImageCheckRow<String>>("question_one", selectionType: .singleSelection(enableDeselection: true))
form.last!.header = HeaderFooterView(title: "Are you a registered member?")
form.last!.tag = "question_one"
for option in userAnswer {
form.last! <<< ImageCheckRow<String>(option){ lrow in
lrow.title = option
lrow.selectableValue = option
lrow.value = nil
lrow.tag = "question_one"
}
}
SelectableSection<ImageCheckRow<String>>("question_two", selectionType: .singleSelection(enableDeselection: true))
form.last!.header = HeaderFooterView(title: "Have you managed to do ...")
form.last!.tag = "question_two"
for option in userAnswer {
form.last! <<< ImageCheckRow<String>(option){ lrow in
lrow.title = option
lrow.selectableValue = option
lrow.value = nil
lrow.tag = "question_two"
}
}
I tried adding the low.tag based on the answer in this question Upload Eureka form data to firebase
but the problem remains.
it looks to me you are adding 2 options with the same tag...
shouldn't you use:
lrow.tag = "question_one_" + option

VB6 - How could I get the ListBox selected id

AS I using the VB6.0 for create a Dialog Box with the ListBox, but only I can get the String text with Trim(DlgText$("xxxxx")), for the other side still I could not found how to get it.
Most of the answer from network said that could be using [LisBox_ID].Selected to get the item that what they want, but I can not get the same result.
For my Code:
[Dialog]
Function aOpenDialog As Boolean
aOpenDialog = False
iArrayLoop = 0
Begin Dialog UserDialog ,,250,120,ScriptTitle,.ActivateDlgControls
Text 5,5,130,10,"Sub Booking End Date", .tf_InsertionSetEndDate
ListBox 5,15,100,100,aArrayList, .aArrayList
Text 110,5,130,10,"After Date [DD-MMM-YYYY]", .tf_AfterDate
TextBox 110,15,55,10, .txt_AfterDate
Text 110,25,55,10,"Change Reason", .tf_ChangeReason
TextBox 110,35,130,10, .txt_ChangeReason
OKButton 110,45,70,10, .btn_Save
CancelButton 110,55,70,10, .btn_Cancel
End Dialog
Dim dlg As UserDialog
aArrayList(1) = "Day1"
aArrayList(2) = "Day2"
Dialog dlg
End Function
[ActiveDlgControls]
Function ActivateDlgControls(ControlName$, Action%, SuppValue%)
If (Action% = 2 And ControlName$ = "btn_Save") Then
sMissingMessage = ""
If (Not IsDate(CStr(Trim(DlgText$("txt_AfterDate"))))) Then
sMissingMessage = sMissingMessage & "- Please input the correct day format"
Else
MsgBox Format(Trim(DlgText$("txt_AfterDate")), "dd mmm yyyy")
' This Area will be using for get the selected array item id
' I can found the selected items with String
MsgBox Trim(DlgText$("aArrayList"))
' Unknow way to found the selected items id
' MsgBox dlg.aArrayList.SelectedItem(x)
End If
If (sMissingMessage <> "") Then
ActivateDlgControls = 1
iCheckResult = 1
sMissingMessage = "Information Missing:" & sMissingMessage
MsgBox sMissingMessage
End If
ElseIf (Action% = 2 And ControlName$ = "btn_Cancel") Then
iCheckResult = 2
End If
End Function
Any idea how should I get the selected ListBox item?
I want to get the array number that I selected inside the LisBox.
Although I got an other stupid idea for get the index like as below code:
For iArrayLoopCheck = 0 To UBound(aArrayList)
If (aArrayList(iArrayLoopCheck) = Trim(DlgText$("aArrayList")))Then
MsgBox "You Select item: " & iArrayLoopCheck
Exit For
End If
Next
Still I was looking for any smart code/ items/ easy way to get the result quickly just like get the String value in array like: Trim(DlgText$("xxxxx"))
Best Regards,
KT
To get the selected index of the list box:
list.ListIndex
returns 0 if the first item is selected, 1 if the second item is selected, etc., and -1 if no item is selected.

Having trouble in adding number in 0.0 decimal

i am using react.js for some of my views! i changes my column max_budget to decimal and added default as 0 so now the default is 0.0!
i have a button and on clicking it, it adds 2 to max budget every time it is clicked! the problem i am facing that!
the default is 0.0 and every time i click the button to add 2 to that 0.0 to make it 2.0 it messes it up and add 2 at the end on 0.0 as 0.02 and if i press it few times it keep added 2 at the end like 0.022222
the button code is:
changeTip: (e) ->
e.preventDefault()
name = e.currentTarget.name # http://www.w3schools.com/jsref/event_currenttarget.asp
if name == "increase"
max_budget = #props.max_budget + 2
else
max_budget = #props.max_budget - 2
data = max_budget: max_budget
#props.saveJobValues(data)
how should i fix it so on adding 2 it shows me 2.0 instead of 0.02
Use HTML5 with
<input type="number" min="1.0" max="5.0" step="0.01">
to accept only float values as input. It will accept "." followed by number also, but reject ".", (<input type="number" min="1" max="5"> for decimals.)
Change your code to
changeTip: (e) ->
e.preventDefault()
name = e.currentTarget.name # http://www.w3schools.com/jsref/event_currenttarget.asp
if name == "increase"
max_budget = parseFloat(#props.max_budget) + 2.0
else
max_budget = parseFloat(#props.max_budget) - 2.0
data = max_budget: max_budget
#props.saveJobValues(data)
(add parseFloat as #Mischa mentioned). I recommend to write "2" as "2.0" for readability (so it's easier to see that you deal with floats)

Omniture tagging - Fire a start event on Onchange (Not Working !!!!)

I am a newbie to Omniture tagging. The company has provided specs and I am following that. I want to fire a start event when the value in the dropdown changes. I don't know what I am missing because it refuses fire the event. I am using Omnibug to test.
<select name="seltest" onChange = "var s=s_gi('ds-prod');tmsomni.linkTrackVars=
'prop6,prop64';tmsomni.linkTrackEvents = 'event54';tmsomni.prop6 = 'vehicle
request';tmsomni.prop64 = 'vehicle'; s.tl(true, 'o');">
<option>1</option>
<option>2</option>
</select>
Your setting the tracking object to s and then using tmsomni to set values in the tracking object. It should look more like this:
<select name="seltest" onchange="window.tmsomni=s_gi('ds-prod');tmsomni.linkTrackVars= 'prop6,prop64';tmsomni.linkTrackEvents = 'event54';tmsomni.prop6 = 'vehicle request';tmsomni.prop64 = 'vehicle'; tmsomni.tl(true, 'o');">
<option>1</option>
<option>2</option>
</select>
Or perhaps the inverse where you would replace all tmsomni with s.
Also set the events variable as below:
<select name="seltest" onchange="window.tmsomni=s_gi('ds-prod');tmsomni.linkTrackVars= 'prop6,prop64';tmsomni.linkTrackEvents = 'event54';tmsomni.events = 'event54';tmsomni.prop6 = 'vehicle request';tmsomni.prop64 = 'vehicle'; tmsomni.tl(true, 'o');">
<option>1</option>
<option>2</option>
</select>
It worked , I was missing the name of the link.

How to preselect an item using Javascript when the page renders

I have a drupal rendered webform that generates the following HTML for a SELECT list. The list is essentially for booking a table in a restaurant. My client wants me to preselect the meal based on the time of the day. So if its between midnight and 3:00 pm Lunch should be preselected automatically. After 3:00 pm till 10:30pm the form should display with dinner preselected.
<select class="form-select required" name="submitted[meal]" id="edit-submitted-meal">
<option selected="selected" value="1">Lunch</option>
<option value="2">Dinner</option>
<option value="3">Sunday Dining</option>
</select>
I created the following JS snippet hoping to achieve the objective but it doesn't seem to work on Page load
window.onload() {
var today = new Date("<?php echo date("Y-m-d H:i:s"); ?>");
var day = date.getDay();
var hour = date.getHours();
var meallist = document.getElementbyId("#edit-submitted-meal");
if (day == 0) {
meallist.options[3].selected==true;
}
else {
if (hour > 15 && hour < 22) {
meallist.options[2].selected==true;
}
else if (hour > 22 && hour < 24 {
meallist.options[1].selected==true;
}
else if (hour > 0 && hour < 15 {
meallist.options[1].selected==true;
}
}
}
Would appreciate any help. Thank you in advance.
PS : The PHP code injects the date into the javascript so when the page is rendered the line becomes var today = new Date("2013-01-15 15:49:45");
You have an error in your javascript syntax
window.onload(){
//your code here
}
should be
window.onload = (function(){
//your code here
});
Also when using document.getElementById you don't want to include the '#'
and for setting a variable as in
meallist.options[1].selected==true;
you only want to use a single =
meallist.options[1].selected=true;
Also bear in mind that the options array is 0 based. E.g options value=3 is actually
meallist.options[2] not [3]
A simplified version can be found here
http://jsfiddle.net/N7Yhr/
Do you have any other errors in your console window (firebug etc)?

Resources