I have write code for select date from date picker in protractor.But this code not working.Unable to select date
var tbl = element(by.xpath(".//*[@id='content-wrapper']/div/div/div/div /div[1]/div/form/div[4]/div/p/div/ul"));
var rows=tbl.element(by.tagName("tr"));
var columns=rows.element(by.tagName("td"));
for(var i=0;i<columns.length;i++)
{
var st=columns.get(i).getText();
if(st.toEqual("13")){
columns.get(i).sendKeys(protractor.Key.ENTER);
}
console.log(st);
browser.sleep(3000);
}
All lines of code you placed are promises, so you first need to resolve each of them before you can use the result. For example, columns.get(i).getText()
is a Promise, you first need to do the following before you can use the value
columns.get(i).getText()
.then(function(tdText){
console.log('tdText = ',tdText);
});
You can also use a filter method on all the td
's like this, see the Protractor documentation :
// Get all the columns in a table, this will resolve in a ElementArrayFinder
// The filter will loop over each element in the ElementArrayFinder
$$('table td').filter(function(elem, index) {
// For each found td, get the text
return elem.getText().then(function(text) {
// when a match is found, return it, else go to the next element
return text === '13';
});
// If an element is found based on the text it will return an ElementArrayFinder
// with 1 result, get the first element and for example click on it
}).first().click();
Hope this helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.