-2

I'm using protractor (jasmine, typescript) and need a help with this case:

I have a structure like this:

<div class="row">
  <span class="name1">
    name
  </span>
  <i class="close-icon1">
   close
  </i>
</div>
<div class="row">
  <span class="name2">
    name
  </span>
  <i class="close-icon2">
    close
  </i>
</div>

And I need a function like:

public clickRemove(itemName: string): void {
  // some code
}

this code needs to search trough the 'rows', find the 'itemName' and click on its 'close'; Any ideas to as to how to solve this?

tz0
  • 307
  • 1
  • 9

2 Answers2

-1
    public clickRemove(itemName: string): void {

    let itemsArray = element.all(by.css('div.row>span'));
    let closeIconArray = element.all(by.css('div.row>i'));

    for(let i=0;i< itemsArray.count();i++){
    itemsArray.get(i).getText().then((Name: string)=>{
    if(Name===itemName){
    closeIconArray.get(i).click();
    }
   }
 }}

Hope above function helps you.

Madhan
  • 1,350
  • 1
  • 4
  • 12
-1
public async clickRemove(itemName: string) {
   let element = await element(by.xpath(`//span[contains(text(),"${itemName}")]/following-sibling::i`))
   await element .click()
   await console.log(`${itemName} removed`)
}
technodeath
  • 123
  • 3