I will try to simplify my explanation.
https://codepen.io/jordan_gio/pen/QeRNZr
Check it out.
When It works : Don't click Remove. Try to select one or more items. It works right?
When it doesn't work: Now try to remove the first one(Remove button after the first item). Then try to select checkboxes once again. After removal, both of them get selected and then I can't choose multiple checkboxes.
You use an index of the item as the key and then transform the array. It is not a good idea. To solve your problem use e as a :key instead of index.
<li v-for="e in options">
<v-checkbox
:key="e"
...
Related
Is there a way to remove the preselected option in <select> element, like it happens with mat-select?
I mean that I don't want the first element of the array to be preselected in the element, but without adding an "empty" entry. I want something like this:
Is this possible with native select?
just include another option at the top:
<mat-option>None</mat-option>
I have a drop down built with extJS.
<input id="combo-1786-inputEl" data-ref="inputEl" type="text" size="1" name="Query Category" placeholder="Select query category" role="combobox" aria-hidden="false" aria-disabled="false" aria-readonly="false" aria-invalid="true" aria-required="true" aria-haspopup="true" aria-expanded="false" aria-autocomplete="list" class="x-form-field x-form-required-field x-form-text x-form-text-default x-form-invalid-field x-form-invalid-field-default x-form-empty-field x-form-empty-field-default" autocomplete="off" data-componentid="combo-1786" data-errorqtip="<ul class="x-list-plain"><li>This field is required</li></ul>" aria-describedby="combo-1786-ariaErrorEl">
As we can see the tag used is 'input' and not 'select'.
So when I looked up about how to populate it, most answers were made under the assumption that it was created using a 'select' tag and it did not work.
Also the drop downitems are fetched from DB only when I click on the arrow on the dropdown:
So as a result of this, the drop down items cant be found on the page source.
Can someone one please suggest how to populate such downs using the best practice?
P.S-I do have a workaround, but its not at all good code practice and not at all generic:
driver.findElement(By.xpath("//*[#id='combo-1731-trigger-picker']")).click();//clicking on the arrow key of the drop down.
//Once the drop down item comes, I am trying to replicate pressing the keyboard arrow key,by sending down arrow key to the drop down item(web element)
//This works for me because I know the extact position of my drop down item in the drop down item list.It will stop working if the postion of the drop item changes
//so below loop just presses the down arrow key required number of times.
for(int i=0;i<5;i++){
driver.findElement(By.xpath("//*[#id='combo-1731-inputEl']")).sendKeys(Keys.ARROW_DOWN);
}
driver.findElement(By.xpath("//*[#id='combo-1731-inputEl']")).sendKeys(Keys.ENTER);
If you read the comments mentioned along with the above code, then you can understand how fragile the logic is.
Please help.
You are trying to click/ select the item in the drop down correct?
Do the drop down items have unique id's? If so you should be able to just pass it the specific xpath id.
I personally use Css to find elements, in that case it would be
driver.find_element(By.CSS_SELECTOR,'#combo-1731-trigger-picker').click()
driver.find_element(By.CSS_SELECTOR, '#combo-1731-inputEl > nth:child(x)').click()
where x = the count of your drop down item.
or if they have unique id's then use
driver.find_element(By.CSS_SELECTOR, '#theUniqueIdGoesHere').click()
I wrote a whole weeks worth of tests, using xpath selectors, it was painful day to day running the test and watching it fail. Going back and changing everything to Css selectors has saved me many head aches since I started writing Auto tests.
Edit: you could try the following,
driver.findElement(By.linkText("Your Links Text Here")).click();
This will only work if each links text is unique as well, if not it will select the first one it finds.
If these work for you would you mind accepting my answer?
I am having an issue trying to find a node that doesnot have text but their child has an specific text.
Here is an example of the html code:
<strong>
This is not
<span>the one</span>
</strong>
<strong>
<span>the one</span>
</strong>
So I need to find the second strong.. but the xpath that I am using is this one:
//strong/span[text()='the one']
This brings me the two elements ... but I need the second one.
I tried something like this:
//strong[not(text())]/span[text()='the one']
but it didn't work..
Any idea how to accomplish this?
Try this one:
//strong[not(normalize-space(text()))]/span[text()='the one']
Use Index to identify the position. But note that here indices start from 1.
(//strong/span[text()='the one'])[2]
I have a select element on my form. I fill its contents with javascript. The view model has a property called Fruits of type IEnumerable. Is it possible to bind this select to that property when I submit the form? So to make it clear, assume there's a form with a select of size 5, which at the same time is empty. Then I add some items (options) to that select with java script:
<select size="5">
<option value="1">Apple</option>
<option value="2">Banana</option>
<option value="3">Grape</option>
<option value="4">Pinapple</option>
</select>
When I submit the form, I want the Fruits property to contain the above option values. How's that done? I can't think of any way to do it.
Finally found it, something's missing though. To overcome the first problem of getting an empty ListBox on the view I did this:
ListBoxFor(x=>x.Fruits,new List<SelectListItem>(),new{style="width:160px;display:block"})
This will bring up an empty <select multiple="multiple" size="5" name="Fruits"> to the view. Then I add some items to the listbox with javascript (to be precise, add options to the select). The biggest pain started after this. When submitting the form the Fruits property was null, so listbox items were not getting bound. After lots of digging I discovered that in order for a ListBox items to bind to some collection the desired ones need to be selected. So even if there're 10 items in the listbox, they won't get bound to my Fruits model property unless I select them before submitting. After selecting the added items the Fruits property contained the corresponding values. However I hate to have to select all the items after adding them. I know this can be done automatically with javascript, but it'd be good to bypass this by some other means.
For the below code
<li class="user ui-menu-item" role="presentation">
<a id="ui-id-52" class="ui-corner-all" tabindex="-1">
<em>User:</em>
Staff User
</a>
</li>
This is the scenario:
There is a text field, in which I enter the name Staff, with that the related values for the staff are displayed in the dynamic list box, in the above scenario the id is dynamically generated, and when I tried to select the value by class, it is same for all the elements.
I want an xpath expression to select the first available options in the list. I tried in many ways like with contains and starts-with, but no use. Please let me know your valuable suggestion.
Thanks in Advance
Shiva.
I think this should work
WebElement ele = webdriver.findElement(By.Xpath("//li[#class='user ui-menu-item'][1]"))
Did you try forming a List and then just directly using the first element of that List?
List<WebElement> list = driver.findElements(By.xpath("//li[#class(contains, 'user')]";
list[0].getText();
I'm still not 100% percentage sure what you want to do with the element once you have found it though. It would probably be better to form the List, then iterate over that list and perform whatever action you require per element.
Use this xpath
"(.//a[#class='ui-corner-all'])[1]"
source: XPath query to get nth instance of an element
Use the xpath. It should work
//li[#role = 'presentation']//a[1]