Enter on cypress after type is not input the value - dom

I just did a cypress curse on Udemy and I am trying to learn a bit more.
I am using this simple code line to get a box and enter a value inside using type and enter, however I am getting no error and the value is not showing inside the box.
here is the code line cy.get('[class="multiselect__tags"]').eq('10').type('2,000,000{enter}')
how I am new I am using index to get the box since in the page there is more than 18 boxes with the attributes.
cy.get('[class="multiselect__tags"]').eq('10').type('2,000,000{enter}')
cy.get('[class="multiselect__tags"]').eq('11').type('2,000,000{enter}')
cy.get('[class="multiselect__tags"]').eq('12').type('1,500{enter}')
Here is the DOM
here is how it shows in the test

The Vue-multiselect control allows the user to select items from a list, or type a value and press enter to select it.
The result is a "tag" for each of the selected items is added to the input box.
To select by typing, this is how it can be done on the demo page
it('selects from vue-multiselect by typing', () => {
cy.viewport(1000,1000)
cy.visit('https://vue-multiselect.js.org/')
cy.get('div.multiselect').eq(0) // there is no id to work with so just get 1st
.type('NO Dependencies{enter}'); // select an item
cy.get('div.multiselect').eq(0) // same parent as above
.within(() => { // now work within that select
cy.get('span.multiselect__tag') // check the tags
.should('have.length', 1) // only one selected
.invoke('text')
.should('contain', 'NO Dependencies') // has the expected text
})
cy.get('div.multiselect').eq(0) // same select
.type('GitHub Stars{enter}'); // select another item
cy.get('div.multiselect').eq(0)
.within(() => {
cy.get('span.multiselect__tag') // check the tags
.should('have.length', 2) // now two selected
.invoke('text')
.should('contain', 'GitHub Stars') // has the expected text
})
})
To select by clicking the dropdown list
it('selects from vue-multiselect by clicking', () => {
cy.viewport(1000,1000)
cy.visit('https://vue-multiselect.js.org/')
cy.get('div.multiselect').eq(0)
.within(() => {
cy.get('div.multiselect__select').click() // open the dropdown
cy.get('li.multiselect__element')
.contains('NO Dependencies')
.click() // select an item
})
cy.get('div.multiselect').eq(0) // same parent as above
.within(() => { // now work within that select
cy.get('span.multiselect__tag') // check the tags
.should('have.length', 1) // only one selected
.invoke('text')
.should('contain', 'NO Dependencies') // has the expected text
})
})
In your web page, the multiselect has a data-vv-name attribute which should pinpoint the particular control we want,
const controlSelector = 'div.multiselect[data-vv-name="data.eoConditions.liability"]';
cy.get(controlSelector)
.type('2,000,000{enter}'); // select an item
cy.get(controlSelector) // same parent as above
.within(() => { // work within that control
cy.get('span.multiselect__tag') // check the tags
.should('have.length', 1) // only one selected
.invoke('text')
.should('contain', '2,000,000') // has the expected text
})
})
I'm not sure if you can select two values on this particular control, it does not make sense to do so since there could be only one liability limit.

Related

react-bootstrap-typeahead How do I trigger a callback (update state) on `Enter` but not when the user is selecting hint?

I'm trying to make an input that will allow user to select multiple items. When finished selecting, he can press Enter to push his selections into an array in the state. The input will then clear and be ready for his next set of selections. (Imagine populating a 2-d array quickly). However, with the code below, if the user presses Enter to select the hint, my callback, pushToState, will trigger as it's in onKeyDown. What's the correct way to implement this behavior?
<Typeahead
id="basic-typeahead-multiple"
labelKey="name"
multiple
onChange={setMultiSelections}
options={options}
selected={multiSelections}
onKeyDown={(event) => {
if (event.key === 'Enter') {
pushToState(multiSelections);
setMultiSelections([]);
}
}}
/>
Your use case is similar to the one in this question. You basically need to determine whether the user is selecting a menu item or not. You can do that by checking the activeIndex of the typeahead:
// Track the index of the highlighted menu item.
const [activeIndex, setActiveIndex] = useState(-1);
const onKeyDown = useCallback(
(e) => {
// Check whether the 'enter' key was pressed, and also make sure that
// no menu items are highlighted.
if (event.key === 'Enter' && activeIndex === -1) {
pushToState(multiSelections);
setMultiSelections([]);
}
},
[activeIndex]
);
return (
<Typeahead
id="basic-typeahead-multiple"
labelKey="name"
multiple
onChange={setMultiSelections}
options={options}
onChange={setMultiSelections}
onKeyDown={onKeyDown}
selected={multiSelections} >
{(state) => {
// Passing a child render function to the component exposes partial
// internal state, including the index of the highlighted menu item.
setActiveIndex(state.activeIndex);
}}
</Typeahead>
);

to detect column content in new row in ag-grid for angular2

I am trying to add a new row dynamically when user selects 'NEW' in ag-grid. It has only one column. And I tried so hard to capture the value in the column without selecting any other column or press 'ENTER'. But most of the methods in ag-grid would detect the changes only some event fires.
[I have to use (keyup) method to detect the text entered but it doesn't detect the][1] column dynamically. I tried (cellClicked), (cellChanged) or getSelectedNodes() etc. I also tried 'checkBoxSelection'.But not able to capture the column value.
Appreciate your help on this. Attached the link for the image. Inserted the code. I can capture the userentered value in the column when he selects ADD but not able to capture with out going to other tab or press 'ENTER'.
private onCellValueChanged($event) {
console.log('onCellValueChanged');
const updateData: Object = {
_id : $event.data._id,
AN_workingGroups: $event.data.AN_workingGroups
}
console.log(updateData);
this.service.updateAnnexData(this.workingGroups, updateData).then((data) => {
console.log(data)
});
console.log('onCellValueChanged: ' + $event.oldValue + ' to ' + $event.newValue);
}
[1]: https://i.stack.imgur.com/9MfIi.pngenter code here

How to remove selection after replace in vscode API

while creating an extension for vscode I got stuck in selection, now the problem is when I replace some range of textEditor through an api it replaces that range as well as make that range selected. For snippets this is a good idea but my extension requirement is not to select replaced text, I searched in api but did't find anything related to remove text selection (Selection occurs when the document is empty)
editor.edit((editBuilder)=>{ //editor is an object of active text editor
editBuilder.replace(textRange,text) // text = 'dummydummydummy'
}) //after this I got the following output
editor.edit(builder => {
builder.replace(selection, newStr);
})
// The edit call returns a promise. When that resolves you can set
// the selection otherwise you interfere with the edit itself.
// So use "then" to sure edit call is done;
.then(success => {
console.log("success:", success);
// Change the selection: start and end position of the new
// selection is same, so it is not to select replaced text;
var postion = editor.selection.end;
editor.selection = new vscode.Selection(postion, postion);
});
I believe that this is happening because the edit is being applied within the current selection. edit returns a promise that is resolved when the edit is applied, and you can use this to set the selection after the edit is successful:
editor.edit((editBuilder) => {
editBuilder.replace(textRange, text)
}).then(success => {
if (success) {
// make selection empty
editor.selection.active = editor.selection.anchor
}
})
let editor = vscode.window.activeTextEditor;
let selection = editor.selection;
editor.edit(builder => {
builder.replace(selection, newStr);
});
see: TextEditorEdit API Doc

How to use selenium webdriver to select an option of Bootstrap select dropdown menu?

I've to select a country from dropdown of https://www.parcelhero.com but when I use the below code for it, sometimes it works sometimes not, giving error of Element not found(xpath("//*[#id='dvQuoteFrom']/div/button"))
driver.findElement(By.xpath("//*[#id='dvQuoteFrom']/div/button")).click();
Thread.sleep(4000);
WebElement txt = driver.findElement(By.xpath("html/body/div[14]/div/div/input"));
txt.sendKeys("Great Britain");
List <WebElement> InnerDropdown1 =driver.findElements(By.xpath("//*[#class='active']"));
for(WebElement option1 : InnerDropdown1)
{ System.out.println(option1.getText());
if(option1.getText().contains("Great Britain")) {
option1.click();
break;
}
}
When I used
WebElement txt = driver.findElement(By.className("bs-searchbox")); then also I got the uable to find element error.
Please help me to select a country of my choice from the country dropdown?
Try doing this. I've changed a few of your locators and tested this on the page you mentioned.
public void foo() {
driver.get("https://www.parcelhero.com/");
//This will be your dropdown button. This needs to be clicked first.
driver.findElement(By.xpath("//button[contains(#data-id,'ConsignorAddressCountryId')]")).click();
//These are your input boxes. I found 3 input boxes on the same page having the same identifiers. We dont want to rely on using index based xpath so here we'll get all instances of input boxes.
List<WebElement> elems = driver.findElements(By.xpath("//*[contains(#class,'bs-searchbox')]//input"));
for (WebElement elem : elems) {
//Here we check if the input box is visible. If I'm not mistaken, there will only be 1 visible input box at a time because you have to click on the dropdown button first.
if (elem.isDisplayed()) {
//If visible, just enter your country of choice
elem.sendKeys("American Samoa");
//Assuming you always enter exact match string for your test, you can use the org.openqa.selenium.Keys for sendKeys()
elem.sendKeys(Keys.ENTER);
break;
}
}
}

Knockout select binding

How to prevent select change event fires when the select biding is initiated? an add button on the page that will add select dynamically to the DOM. when each select box is adding to the DOM, the change event is firing rather than I select the item from the select?
The thing is that KnockoutJS attempts to find which element of your listbox matches the requiredItem observable. There is none in the beginning, which is why it then attempts to set it to the "caption" of the listbox. You did not provide one, so it sets requiredItem to the first element of the listbox.
What you could do is add a caption item to your array:
self.requireditems = ko.observableArray([
{ desc: "Select an option from the list...", key: 0, editable: false } // ... and then all other items]);
and if you really don't want requiredItem to be updated:
self.selectedItem = ko.observable(self.requiredItems()[0]);
Then if you want to know if a valid element has been selected from the list, you could add the following property:
self.isValidSelectedItem = ko.computed(function() {
return self.selectedItem().id;
});