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.
Related
I'm very new to Javascript and it's my only second week using Cypress, so I need help in getting radio buttons to be clicked. I'm getting errors from Cypress all the time.
The element that I'm trying to check looks like:
<input class="XyzTypeRadio" type="radio" name="zzz_type" value="2">
And what I tried to implement after reading the Cypress documentation (at https://docs.cypress.io/api/commands/check.html#Syntax )was:
cy.get('[type="radio"]').first('.XyzTypeRadio').check('value=2')
Also tried simply .... .check('2') and ... .check('Xyz')
(edited and working answer)
Try this:
cy.get('[type="radio"].XyzTypeRadio').check("2")
Or if you don't care which radio button is checked, you could check the first one:
cy.get('[type="radio"].XyzTypeRadio').first().check()
Takeaways:
The first() function does not understand selectors, that's why we need to pass our selector ".XyzTypeRadio" to get().
The check() function expects the value or values as its argument, so instead of "value=2" we simply give it "2".
The check() function does a bit of selecting, ie the result of everything before calling check("2") is a list of inputs and the check("2") function searches and selects the one whose value is "2".
We could use first().check() if we want to check the first radio button, or we could remove first() and check a radio button with a specific value using check("2").
cy.get('[value="Other"]').first().check()
this worked for me as there are 3 radio buttons each with a value so it was just a matter of selecting the correct value
I am encountering strange behavior in a small Elm program with an HTML select element.
The options initially include an empty first item with a value of "" and 3 additional items with values "bar", "baz", and "foo".
When the page initially displays, the empty first item is selected, as expected.
If the dropdown is then clicked and "bar" is selected from the list, the dropdown then shows, and selects "baz", not "bar". Note that when an item is selected, the select element is re-rendered without the empty first option.
Here is code that demonstrates this problem.
Why is this occurring? Should I just leave the empty first item in the select options? That will leave an empty "slot" in the dropdown. Can this be avoided?
I initially found this in Chrome, but it also occurs in Firefox, so I suspect I am violating something in the HTML specification.
First off I just wanted to say, thank you for isolating the issue and giving us a small sample project that demonstrates the issue. It took a bit of digging, but I discovered that the html 'selected' attribute, is to set the selected value at page load. So updating it after page load will cause odd behaviors, we are to use 'value' instead. And on the flip side, setting 'value' on page load is ignored! Thanks html! ;) Source here
See revised code here
I'm trying to complete a happy path e-commerce payment test but I cant seem to click on the nested element for credit card to be honest I'm not entirely sure which is the clickable element.
Any help to get this working would be appreciated.
When inputting forms, you typically want to interact with input and select elements. In this case, you can see that the visible input field is a radio button - ie <input type="radio">.
You access radio buttons using the radio method and select it by using the set method:
browser.radio(id: 'cc-payment').set
The element you want to click is the input with type radio. You should be able to do something like:
driver.find_element(:css, "input[id='cc-payment'][value='creditCard']").click
I'm curious if clicking on the parent item would resolve.
#browser.input(id: 'cc-payment').parent.click
If the div registers the click and sets the input then this might work. You should be able to manually verify this beahviour by clicking outside of the radial and seeing if it selects.
How to check that Ajax call returns no items for populating a drop down list with WebDriver?
I've tried different timeout and waiting options for elements. Nothing works.
From the user perspective, he enters some value in the text field, waits for ajax call return and then empty dropdown list appears and suddenly disappears.
So suppose I have autosuggest input field (like google search) and I need to be sure that there were no auto suggestions for the selected input.
Hard to tell without seeing the markup, but there is usually a container (probably a <div> element) for showing the ajax results, it is probably hidden (ie using display: none;) and becomes visible after databinding occurs. If i were you, i would locate that element and use it in WebDriverWait, perhaps using ExpecedConditions.invisibilityOfElementLocated
The application is written in ASP VB classic and various Java scripts. I am faced with some issues
1) When I select an entry in a dropdown box, I can use the "onBlur" method to do what is needed at that point
What is the method available for an AutoSuggest Textbox that I can employ once
a) The desired entry is selected from the list (such as "onSelect").
b) The user never selects, but actually types the entire selection manually. In that case, I would need a method such as "onBeingDoneTyping"
2) When a regular dropdown is defined, I can display a user friendly description (like first and last name). In the meantime, internally I can retrieve what the index of that record is with the first entry of the parameter "value", in my case: PatientID.
" " " <%=lsSelected%> ><%=PatientName%>
How can that be accomplished when using the AutoSuggest feature in a textBox?
Say I allow "First-Name Last-Name"
Is there a hidden parameter that can be used that would let me know the index of the selected entry?
In addition, should I create a column in the data base "FirstLastName" to speed up the search?
For (1) you're after an auto-complete function. I've used this jQuery with classic-ASP a few times (excellent little plugin): http://docs.jquery.com/Plugins/Autocomplete - there's a good demo and example source there.
For (2) - assuming that you're using the jQuery plugin, then your object is a textbox, not a select object. So if the textbox you created is:
<input type="text" name="example" id="example" />
when the form is submitted any request.form("example") will return the text entered, not the index/selected value from any list of options.