I'm working with Selenium Webdriver using ruby.
I have a dropdown and after each value/text selected inside it, I want to extract that value/text visible on webpage interface without html tags, because for that value selected, in div > option tag I do not have a specific attribute for it, to figure out which is the value, can I do that in selenium webdriver using ruby?
Edit : HTML code :
<select name="OwningAndUsingCarPanel.UseOfVehicle" id="OwningAndUsingCarPanel_UseOfVehicle" autocomplete="off">
<option value="0" selected="selected">Please select</option>
<option value="227">Social only</option>
<option value="228">Social including commuting to a single place of work</option>
<option value="229">Business use by you</option>
</select>
UPDATE - more details:
I've tried this method and it's working if you select previous some value, but in my case I have some bug in my dropdown values, something like this: have 5 dropdowns one after another, and each of them is depending on the previous dropdown, so if i begin to fill the form like this:
1). select value at first dropdown (take the text)
2). select at the second dropdown some value (take the text)
3). select at the third dropdown some value (take the text)
4). select at the fourth dropdown some value (take the text)
5). select at the fifth dropdown some value (take the text) (this dropdown is generated by the previous fourth dropdowns values) - now the second value of dropdown is changed on the interface webpage. (so here I cant put element.text for the second dropdwon because it extract the value I have selected point 2).
I want to check if after each selecting value the previous value remain the same on the webpage inteface, in my case I have some bug at this.
You can get the value of the textfield using attribute :
element['value']
For any other element you can get the text using :
element.text
You can just do element.text to get the display value of an element.
Related
I am trying to get the default selected value from a dropdown list. There are no Options or Values in the HTML code that I can see when I inspect the code.
This is what the screen looks like when the user enters it.
If you click the dropdown, you will see that the value 8 is highlighted because it is the default value
The HTML code does not show the value 8 anywhere nor any of the other values listed that can be selected. I need to verify that the default value is 8 but I'm having a hard time finding the correct code to do this.
This is the html:
I can use this Xpath to click on the dropdown button:
//[contains(#class,'label')][text()='Minimum Length']/ancestor::/following-sibling::1//[#role='combobox']//*[contains(#class,'filterselect-button')][#role='button']
This will also click on the combo box and allow the dropdown list to appear
//[text()='${Name}']/parent::/following-sibling::1//[contains(#type,'text')]
I'm working on a script with mechanize in Ruby. I'm trying to select the values of the form(dropdown), however the values for the second field of the form don't appear until the first field has a selection. It prevents the following -
my_form[0].options[2].select
my_form[1].options[2].select
my_form[2].options[2].select
my_form[3].options[0].select
because the second field doesn't have any value at this point. The selection of the first part works like it should, however.
The line in the form looks like this
<select id="DistrictId" name="DistrictId"><option value="">---SELECT---</option>
<option value="3">Alaska Gateway School District</option>
...
</select>
<input type="button" id="selectDistrict" value="SELECT">
I see there is a Select button after the field, however I'm not sure on how to click it and have the second field populate.
When I use the following
my_form.button_with(:value => "SELECT").click
I don't get an error, but it also doesn't repopulate the second field. I tried placing that line after the selection of the first field, and it gets me no further.
I haven't seen anything that is super helpful with dropdown menus.
Use a Login form with Mechanize was helpful in dealing with the form, but didn't help with actually selecting that button.
The other thing that I need this to do is to loop though all of the options in the drop down menus.
I've been able to find some things about dropdowns and python, which has also helped.
I can select the part with the
.options[x]
But I am unsure as to how to know when to end the looping. It looks like the elements are stored as an array, and so I can just do .each do on the forms. http://crabonature.pl/posts/23-automation-with-mechanize-and-ruby was helpful for going through the form, but it all comes back to having to select the top form value before being able to see the values in the fields under it.
I am trying to set the selected value of a select control based on a model in an indexed situation. I have the following code -
<select asp-for="Items.Details[i].One"
asp-items="Utility.DropdownListItems(date, Model.Items.Details[i].One)">
</select>
I am setting the selected item in the Utility that returns the SelectList, and would expect that to set the selected item of the drop down, but that doesn't work. If I inspect the option elements, none have the selected tag.
I know there was an issue with indexed data in previous iterations of Mvc HtmlHelpers. Does anyone know if this was resolved in MVC6?
For both HTML and tag helpers, generated <option> elements are selected based on the expression value (Item.Details[i].One in your case). IsSelected from the select list matters only if the expression value is null i.e. in the Create case.
We have corrected a number of issues related to indexed data in MVC 6. Please file an issue at https://github.com/aspnet/Mvc/issues if something is still not working.
Tablesorter automatically builds the the select element for a column filter based on the settings in filter_formatter. Is it possible for tablesorter to set the <option> value attribute to be different than the label in a dropdown <select> filter in tablesorter when using ajax? It seems that tablesorter sets both to be the same.
For example, I'd like to be able to have the following dropdown to filter on languages:
<select>
<option value="en">English</option>
<option value="fr">French</option>
</select>
Using ajax, the two-letter value is used to query the database, but the full language name is better to show users for understandability.
What you have written above should work. When getting the selected value using javascript, find the select element, (call it var selectBox), and then selectBox.value will be the 'value' of the selected element. So if 'English' is what's showing as chosen, selectBox.value will equal 'en'.
I am using mvc3 and have a dropdownlist (using DropDownListFor helper). I set the selected value to my default value. When the user selects a different item, the selected property of that item is not marked as such, i.e. the default value still has the selected property in the rendered html. Is this normal behaviour? If i use jquery and get the ddl val property it is correctly set to the recently selected item...is this just how dropdownlists work? I've checked IE, FF, Chrome and IE doesnt even have a selected property next to the options...
Edit:
Infact ive just tested it with firefox 9 + . It does change the html source with the selected changing place.
<option selected="selected" value="2">(0002) </option>
<option value="3">(0003) </option>
Ensure you are viewing the source of the current(correct) page, and the correct option list. Control + U in Firefox or Chrome.
As you change the dropdownbox, behind the scenes the selected value will have changed. As you have observed. And so submitting etc will use the new selected value.
So its nothing to worry about anyway :)