Selecting a drop-down option using Selenium IDE - xpath

I'm new to Selenium and having a difficult time selecting options from a drop down list (trying to select the second option).
Here is the HTML that I'm working with:
<div id="applicationReasonTypeIDContainer" class="appfield">
<label id="applicationReasonTypeIDLabel" for="applicationReasonTypeID">Application Reason</label>
<select name="appstart_international1:applicationReasonTypeID" id="applicationReasonTypeID" class="AppStart dropdown required" title="Application reason">
<option value="0"> </option>
<option value="1">New Application</option>
<option value="2">Additional location</option>
<option value="3">Owner change</option>
I'm using XPath checker to find the XPath, and it's giving me this but it doesn't work when I try and click or select command
id('applicationReasonTypeID_listbox')/x:li[2]
What should the proper Target be for finding an option like this using XPath?
Thanks Kindly!

If you know the text that will be in the field this is how I do it:
new Select(driver.findElement(By.id("applicationReasonTypeID"))).selectByVisibleText("New Application");
Hope that might help.
edit to add correct id and text from code provided.

What's wrong with either of the following?
new SelectElement(driver.FindElement(By.Id("CustomerDropDown"))).SelectByText("Nationwide");
new SelectElement(driver.FindElement(By.Id("CustomerDropDown"))).SelectByIndex(1);

I actually figured out the problem - it's an issue with Kendo UI not supporting drop-downs properly. Basically the workaround is the click the drop-down arrow, then use sendKeys and point to the same Target as the drop-down with the value being whatever item you want from the list, then clicking the drop-down again. This worked for me, hopefully it helps somebody else!

Related

HTA: Can a Link act as a Select? And How to Store HTA state in a way I can Recover it when I re-open it?

EDIT 2:
Here is exactly what I need:
Change dropdown option with jQuery/Javascript on link click
Whatever, I could not make this to work with the HTA! Any help is much appreciated!
Hello all and thanks in advance for your answers!
I've been working in a self project, and accomplished at least 75% of what I want. Whatever, those two questions on the title are the things that are making me stuck!
Here is one image of how my program looks right now:
Part of my "program"
Ok, as you can see, it has LOTS of drop down menus, and that's ok.
But for ease of use and for questions of aesthetics, I'd like to migrate one of those drop down to the menu on the left.
This select has 5 options, and according to what I chose, it will change something inside a .txt file.
The problem is that I simply CAN'T make this select menu work on the left menu, whatever, as a "select", it work's fine.
Here's an example of the code that's working:
<select size="1" name="OptionChooser43" inputbox id = "searchInput43">
<option value="Equals = 2">Adicionar Expression</option>
<option value="Equals = 3">+ 1 Expression</option>
<option value="Equals = 4">+ 2 Expressions</option>
<option value="Equals = 5">+ 3 Expressions</option>
<option value="Equals = 6">+ 4 Expressions</option>
So, this select works just fine, and changes a part of my .txt with "Equals = &" accordingly.
But if I try to embed it on the left menu, I cant manage it to work.
Here's the code: One of one of the working functions, and another of the non working "select":
Upload
<ul>
<li><a onclick="LoadPreset_1" style="cursor:pointer;">Upload Preset 1</a></li>
<li><a onclick="LoadPreset_2" style="cursor:pointer;">Upload Preset 2</a></li>
</ul>
</li>
*******NON WORKING********
<li><a id="" option value="Equals = 2" style="cursor:pointer;"></option></li>
<li><a id="" option value="Equals = 3" style="cursor:pointer;">+ 1 Expression</option></li></a></div>
I've tried to: Create a new sub for each of the items of the menu, but as soon as I click it, it executes changes to the txt, without execute the changes that I've done with my drop menus.
I tried to use it as a select, but it doesn't answer my commands.
I googled it every way I could think of, no success.
And I even did not want to ask, because it maybe really simple and could make you angry! haha
Second:
I would like to store everything I do on the HTA, in a way that when I open it again, it would be the way I left.
Each drop menu has from 127 to 256 different options, and it would be really nice to have it stored once I open the HTA again!
I also, would like to be able to load the preset-info if I wish.
I've searched how to store data on xml, database... But again, was not successful.
I could go really far alone, but this time I hope you can help me!
Thanks in advance!
Edit: Even after cutting off what I did not need, I still ended up with almost 700 lines, so, here is the attached hta.
HTA File

Calling a Select_List with Watir-Webdriver Without an ID/Name

I'm currently having trouble calling a Select_List that does not have a name/ID (as the title states).
The HTML for the Select List is:
<select dojoattachpoint="userSelector" size="15" multiple="">
<option value="_W2kn2sdAEeSmeMQKjIY8Ug"></option>
<option value="_gkeqUBUqEeG7h6M2lwbcyg"></option>
</select>
What I need to do is select one option in the select list and then click a button, but I can't select the option if I don't know how to point at the list itself.
Note: This is done in Firefox if it matters.
Because "dojoattachpoint" is not a valid attribute for a Select Element per the html5 spec, you can't use it directly. You can access it with css, though:
el = browser.select(css: "[dojoattachpoint='userSelector']")
You could also look into making the site's code html5 compliant, since I think dojo supports data tags: 'data-dojoattachpoint' or the like. Then your selector could be: el = browser.select(data_dojoattachpoint: 'userSelector')

Dropdown list and aria live?

Is it possible for NVDA to read only the dropdown select value when being loaded with aria live?
<div aria-live="polite">
<select>
<option>A</option>
<option selected>B</option>
<option>C</option>
<option></option>
</select>
</div>
Right now on firefox, it will read A,B,C with no notion of which one is selected. When having plenty of options this becomes an issue since all of the options are being read. Is there a way to mark the select to just read the selected value? "B"
Without aria live the dropdown select is read correctly, just reads "B". Is there a way to achieve this while inside aria live?
You should use something like the a11yfy live announcer to announce that the example has been updated and then let the user navigate to find the details of the example.
You can download it from Bower. Documentation is here https://github.com/dylanb/a11yfy/blob/master/announce.md#jquerya11yfyassertiveannounce
The code, in case you want to implement yourself is here https://github.com/dylanb/a11yfy/blob/master/a11yfy/jquery.a11yfy.core.js#L29

How to add image in dropdown in angularjs

I am working on dropdown with image in angularjs, i tried many solution but havent get any success.
My combo data is coming in json format with three elements id , image and value.
These dropdown numbers are also dynamic as per number of rows are there in model.
Please share the solution for that.
Thanks you.
Please Try this it will work out,
<select ng-model="choice">
<option ng-repeat="item in itemsList" data-image="{{item.url}}">{{item.label}}</option>
<select>
<select ng-model="image_chosen">
<option ng-repeat="data in list" data-image="{{data.url}}" value="{{data.id}}">{{data.value}}</option>
<option value="">Choose a option</option>
</select>
Checkout a example at angularjs select option with custom format value
Hope it helps.
Write like this in option tag
ng-repeat="obj in xxxxComboData" data-image="{{obj.image}}"

Selenium click() or isSelected() are not executed on RadioButton's input element

I have radio buttons that are located inside a table, such as:
<tr id="radiofield-1080-inputRow">
<td class="x-form-item-body" id="radiofield-1080-bodyEl" colspan="3">
<input type="button" id="radiofield-1080-inputEl" class="x-form-field" autocomplete="off">
<label id="radiofield-1080-boxLabelEl" class="x-form-cb-label">My Label</label>
</td>
</tr>
I do find the input element, by the following code:
xPath = String.format("//tr/td[contains(#id,'%s')][contains(label,'%s')]/label", xType, text);
webElement = webDriver.findElement(By.xpath(xPath));
but isSelected() or click() doesn't seem to work on it.
Do you have any suggestion?
Haven't used selenium in a while but from a quick google it looks like you should try the isChecked and check/uncheck methods.
Here's the Javadoc but for some reason can't get a decent link, obviously check on the Selenium object. If you're using a different version or if I misunderstood something sorry.
http://selenium.googlecode.com/git/docs/api/java/index.html
In your code snippet problem with locator.
Use any of the below below locators
By.cssSelector("input[id*='radiofield-']");
By.id("radiofield-1080-inputEl")
By.xpath("//tr/td[contains(#id,'radiofield-')]/input")
Try clicking on the "input" instead of the "label".
xpath of input:
"//input[#id='radiofield-1080-inputEl']"
If the input id is not always the same, you can try this, the location of input will be based off the label:
//label[text()='My Label']/preceding-sibling::input
Thanks for all your answers.
My finding concluded with the following:
ExtJS implement radiobutton and checkbox as button, therefore the selenium isSelected() is not functioning.
There is a need to implement isSelected(), as suggested at:
How to check if extjs checkbox is selected in selenium?
The click() does the work, as it is a button.
Thanks again, Michal

Resources