Selenium2Library - Safari not selecting from drop down list - safari

I have two drop downs on a page. I need to verify that the item in drop down list 1 has a class of "selected" added to it when the item in drop down list 2 has been selected. Drop down list 1 has more than 3 options in it but I wanted to save space in the post. The first chunk of steps gets the values for all the items in the list and randomly selects one.
The second portion uses the value that was randomly selected in the first few steps to target the option and see check for the selected class to be true.
Here is the HTML:
<ol>
<li class="select input required" id="message_recipient_input">
<select id="message_recipient_id">
<option value></option>
<option value="1">Smith, Bob</option>
<option value="2">Smith, Steve</option>
<option value="3">Smith, Joe</option>
</select>
</li>
</ol>
<ol>
<li class="select input required" id="message_template_input">
<select id="message_template_id">
<option value></option>
<option value="9">Message Template</option>
<option value="10">Survey Template</option>
<option value="11">Coupon Template</option>
</select>
</li>
</ol>
Here are the steps in RF:
${RecipientCount}= Get Matching Xpath Count xpath=//*[#id="message_recipient_id"]/option
Log ${RecipientCount}
#{ValueList}= Create List
: FOR ${INDEX} IN RANGE 1 ${RecipientCount}
\ ${recipient_value}= Get Element Attribute xpath=//*[#id="message_recipient_id"]/option[contains(text(), '#')] [${INDEX}]#value
\ Log ${recipient_value}
\ Append To List ${ValueList} ${recipient_value}
Log ${ValueList}
${recipient}= Evaluate random.choice(${ValueList}) random
Log ${recipient}
Sleep 2s
Select From List id=message_recipient_id ${recipient}
Sleep 2s
${message_template_dropdown}= Select From List By Value id=message_template_id 9
Sleep 2s
${selected_recipient}= Get Element Attribute xpath=//option[#value=${recipient}] #selected
Log ${selected_recipient}
Should Contain ${selected_recipient} true
This works fine in Chrome and Firefox on Mac OS X but Safari isn't selecting any of the items in the lists. The steps pass as if it is selecting them but fails on the "Should Contain" step because ${selected_recipient} has None for the selected class.

Related

vuejs different v-ifs from a previous select

I am trying to display two different divs according to a select options, but I am only getting the first v-if. When I select "de", I do get the first div content, but I also get it when I select fr, instead of the second div.
I can't get my head around this. Any ideas of what I am getting wrong?
This goes on inside a form:
<select v-model="source" :key="source">
<option :value="de">de</option>
<option :value="fr">fr</option>
</select><br><br>
<div class="characters">
<div v-if="source === de" class="deChars" :key="source">
<h5>Special German characters:</h5>
<li v-for="character in deChars" :key="character">{{ character }}</li>
</div>
<div v-else-if="source === fr" class="frChars" :key="source">
<h5>Special French characters:</h5>
<li v-for="character in frChars" :key="character">{{ character }}</li>
</div>
<br>
</div>
on the script section I am using the options api with the data property source=" ", and two arrays for deChars and frChars.
note: those :key="source" I added to make sure it gets read when the source value changes.
The data properties:
data(){
return {
original: "",
translation: "",
source: "",
target: "en",
deChars: ["ä", "Ä", "é", "ö", "Ö", "ü", "Ü", "ß"],
frChars: ["à", "â", "ç", "é", "è", "ê", "ë", "î", "ï", "ô", "û", "ü", "œ"]
}
},
Thank you so much!
Try to remove the binding sign since it seems that de and fr are not declared as properties and they're just raw string :
<select v-model="source" >
<option value="de">de</option>
<option value="fr">fr</option>
</select>
then do v-if="source === 'de'" and v-else-if="source === 'fr'"
It seems that the problem was with the select options. THe binding seemed to mess about. Once I got rid of that, it works perfectly. So thanks for that Boussadjra. However, if on the v-if I change the de and fr to strings, it does not work. WHich is why I am adding this comment as the solution.

"---please make a choise---" prestashop form

i would like to make default "---please make a choice--'. Actually in checkout adress form state is compilate like italia. I put a screenenter image description here
You need to find block responsible for showing province field and add something like this right above foreach loop:
<option value disabled selected>{l s='-- please choose --' d='Shop.Forms.Labels'}</option>
Example based on "Select a country" located in prestashop\themes\classic\templates_partials\form-fields.tpl:
{block name='form_field_item_country'}
<select
class="form-control form-control-select js-country"
name="{$field.name}"
{if $field.required}required{/if}
>
<option value disabled selected>{l s='-- please choose --' d='Shop.Forms.Labels'}</option>
{foreach from=$field.availableValues item="label" key="value"}
<option value="{$value}" {if $value eq $field.value} selected {/if}>{$label}</option>
{/foreach}
</select>
{/block}

Default value pre-selected in select box with ng-options

I am trying to get default value selected (from database) in my select box using ng-options.
My view
<select class="form-control samlength modalinput"
ng-options="p.procid as p.procname for p in processes track by p.procid"
ng-model="p.procid">
<option value="">-- choose an option --</option>
</select>
where p.procid is a value received from the database.
My data
procid procname time
1 MyProcess 2018-05-30 13:34:54.097 3003162
3 Testing 2018-05-31 18:31:32.467 3003162
If selected procid is 3, how can I get it to be selected by default?
FYI - I have tried multiple answers given in other threads. I have also tried ng-init but nothing helped.
You can keep your HTML as:
<select class="form-control samlength modalinput"
ng-options="p.procid as p.procname for p in processes track by p.procid"
ng-model="selectedProcess">
<option value="">-- choose an option --</option>
</select>
Now if we have a requirement to select a particular object in the array. We can do that by iterating through the array and comparing value at the given key:
function functiontofindIndexByKeyValue(arraytosearch, key, valuetosearch) {
for (var i = 0; i < arraytosearch.length; i++) {
if (arraytosearch[i][key] == valuetosearch) {
return i;
}
}
return null;
}
Call this function as:
var index = functiontofindIndexByKeyValue($scope.processes, "procid", procid);
$scope.selectedProcess = $scope.processes[index];
alert(index);
Hope it works!
Update your html code to this:
<select ng-model="processSelected"
ng-options="p.procname for p in processes track by p.procid">
</select>
Then in controller initialise your model value as:
$scope.processSelected = $scope.processes[1];
Where $scope.processes is an array of process objects.
Plunker Example

Excel VBA Select Option Website Dropdown List

I am trying to automate this website using VBA excel. I am stuck at one point where I need to select value from the drop-down box. I am very much new to this as this is my first such project.
This is what I have coded to select the value:
Set objSelect = objIE.document.getElementById("personTitle")
For Each opt In objSelect.Options
If opt.Value = "Miss" Then
'Debug.Print "found!"
opt.Selected = True
'opt.Selected = "selected"
Else
'Debug.Print "not found!"
opt.Selected = False
End If
Next
I have also tried using the debug.print to check if the value that I am trying to find is actually getting matched or not- and it turns out that it matches.
The only problem I am facing is that the value is not getting set.
Can any of the gurus here please help?
Here is the HTML of that section:
<div class="input-wrap input-wrap__inline">
<div tabindex="-1" class="select is-placeholder"><div class="select_display">Title</div><div class="select_arrow glyphicon glyphicon-chevron-down"></div><dl class="select_list"><dt class="pretend-dd is-hover" data-index="1" data-val="Mr">Mr</dt><dt class="pretend-dd" data-index="2" data-val="Mrs">Mrs</dt><dt class="pretend-dd" data-index="3" data-val="Miss">Miss</dt><dt class="pretend-dd" data-index="4" data-val="Ms">Ms</dt><dt class="pretend-dd" data-index="5" data-val="Dr">Dr</dt></dl></div><select name="personTitle" class="parsley-validated hasCustomSelect .no-change, .bv-dropdown-select is-invisible" id="personTitle" required="" data-required-message="Please select a title">
<option selected="selected" value="">Title</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
</select>
</div>
I think you want a different class. The class in that HTML snippet is select_list. Then the subsequent dt tags.
If you observe the following CSS selector, where "." means class and " dt" means select all dt tags inside elements of that class, you will see it makes the correct selections:
In the code below, I translate this selector into:
ieDoc.getElementsByClassName("select_list")(0).getElementsByTagName("dt")
This assumes that index 0 is the correct one to use for elements of the class "select_list". You can easily inspect the collection to find the right index if you set it to a variable e.g.
Dim x As Object
Set x = ieDoc.getElementsByClassName("select_list")(0).getElementsByTagName("dt")
Code:
Dim currentOption As Object
For Each currentOption In ieDoc.getElementsByClassName("select_list")(0).getElementsByTagName("dt")
If InStr(currentOption.innerText, "Miss") > 0 Then
currentOption.Selected = True
End If
Next currentOption
Here are a couple options to try if you haven't already:
If opt.Value = "Miss" Then
'Debug.Print "found!"
opt.Click
OR
If opt.Value = "Miss" Then
'Debug.Print "found!"
opt.Focus
opt.FireEvent ("onchange")
If this turns out to be something done in kendoGrid or kendoDropDownList, I might be able to help with that also.

Web driver how to select option in DYNAMIC drop down in VBA

I have this HTML
<div class="ui-widget">
<select name="calAlum" style="display: none;">undefined
<option value=""></option>
<option value="5.0">5.0</option>
<option value="5.1">5.1</option>
<option value="5.2">5.2</option>
<option value="5.3">5.3</option>
<option value="5.4">5.4</option>
<option value="5.5">5.5</option>
<option value="5.6">5.6</option>
<option value="5.7">5.7</option>
<option value="5.8">5.8</option>
<option value="5.9">5.9</option>
<option value="6.0">6.0</option>
<option value="6.1">6.1</option>
<option value="6.2">6.2</option>
<option value="6.3">6.3</option>
<option value="6.4">6.4</option>
<option value="6.5">6.5</option>
<option value="6.6">6.6</option>
<option value="6.7">6.7</option>
<option value="6.8">6.8</option>
<option value="6.9">6.9</option>
<option value="7.0">7.0</option>
<option value="7.1">7.1</option>
<option value="7.2">7.2</option>
<option value="7.3">7.3</option>
<option value="7.4">7.4</option>
<option value="7.5">7.5</option>
<option value="7.6">7.6</option>
<option value="7.7">7.7</option>
<option value="7.8">7.8</option>
<option value="7.9">7.9</option>
<option value="8.0">8.0</option>
<option value="8.1">8.1</option>
<option value="8.2">8.2</option>
<option value="8.3">8.3</option>
<option value="8.4">8.4</option>
<option value="8.5">8.5</option>
<option value="8.6">8.6</option>
<option value="8.7">8.7</option>
<option value="8.8">8.8</option>
<option value="8.9">8.9</option>
<option value="9.0">9.0</option>
<option value="9.1">9.1</option>
<option value="9.2">9.2</option>
<option value="9.3">9.3</option>
<option value="9.4">9.4</option>
<option value="9.5">9.5</option>
<option value="9.6">9.6</option>
<option value="9.7">9.7</option>
<option value="9.8">9.8</option>
<option value="9.9">9.9</option>
<option value="10.0">10.0</option>
</select>
when i click on the objetc display all the list but if a press "5" for example the list show only "5.0", "5.1" ,"5.2" etc. and when i press 5.8 only show me "5.8" llike valu to select
So i want to select any option with VBA, (whith other combox i dont have problems but with this have error)
i have tried this
sub CALF()
Dim H As selenium.Keys
*Here find the element "select" whit the name "calAlum"* i dont have problem
For Each element In WEB3.FindElementsByTag("select")
If element.Attribute("name") = "calAlum" Then
element.AsSelect.selectbyvalue Activecell *in this part show error*
End If
Next
MsgBox "fin"
End Sub
but for this drop down doesnt work i tried to use diferent ways but dont work, NOTE: this code go to inside IF
"to focus the box but dont work"
element.click
"to write value dont work"
element.sendkeys "5.8"
"to copy value in clipboard then paste value in the objetc dont work"
WEB3.SetClipBoard ActiveCell.Value
element.SendKeys Control, "V"
but if manually select any value in the object like "9.8" and the in the code use
R= element.value
or
R=elment.attrribute("value")
return "9.8" then i use
element.asselect.selectbyvalue R work
but if i change R= "9.7" and use
element.asselect.selectbyvalue R
return Error value no found
then i tried after to wrap webelement in selectelemnet this
r= element.SelectedOption
r= element.asselect.selectedoption
to know what option is selected, but both return void "" obviusly is rare because R= element.value return "9.8" then i use
element.asselect.options
for i=0 to element.asselect.options
r(i)=element.asselect.selectedoption
next
to know all option are in selectelement "element" but return error its necesary a object so use
r = element.IsSelected
but return false thats to say i cant use the object like webelement and if i wrap to selectelment the object dont have any option, someone can help me.
If you help me how to select the object o how to manipulate object "select" dynamic
CSS selector:
You can use a CSS selector to target the option of choice and then .Click to select. You extract the option value into a variable which you concatenate into the CSS selector string.
Your example:
For your example, you can use selector select option[value='5.0'], where 5.0 is extracted into a variable.
CONST SELECTED_INDEX As String = "5.0"
WEB3.FindElementByCss("select option[value='" & SELECTED_INDEX & "']").Click
Here is an example using Facebook and selecting the drop down day for birthday.
CSS selector for Facebook birthday day:
#day option[value='18']
This reads as element with id "day", containing tag option, with attribute value that is =18. # is id selector and [] is for attribute.
VBA Code:
Option Explicit
Public Sub MakeSelection()
Dim d As WebDriver
Set d = New ChromeDriver
Const URL = "https://www.facebook.com/"
Const SELECTED_INDEX As Long = 18
With d
.Start "Chrome"
.get URL
'Selector was e.g. for day 1 "#day option[value='1']"
.FindElementByCss("#day option[value='" & SELECTED_INDEX & "']").Click
Stop '<= Delete me later
.Quit
Application.ScreenUpdating = True
End With
End Sub