How to iterate in table to find specific text using Protractor?Locating nearest Button Selenium PythonHow do I find an element that contains specific text in Selenium Webdriver (Python)?How to iterate over the keys and values with ng-repeat in AngularJS?How to getText on an input in protractorHow to find specific html elements, AngularJS, protractorProtractor by.repeater not finding anythingHow to find specific row in ng-table by text [protractor]Protractor: How do I select a Radio Button using 'by.repeater'?Can not enter text in input box using sendkeys or javascript in IE11How to find specific row in ProtractorHow to find a specific child element with Protractor

Looking for a soft substance that doesn't dissolve underwater

Plot twist where the antagonist wins

Is it possible to play as a necromancer skeleton?

Where have Brexit voters gone?

Count rotary dial pulses in a phone number (including letters)

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

Website returning plaintext password

Did people go back to where they were?

Make 24 using exactly three 3s

The art of clickbait captions

How to Pin Point Large File eating space in Fedora 18

In the current era, do any wizards survive from 1372 DR?

Should I disclose a colleague's illness (that I should not know) when others badmouth him

At what point in European history could a government build a printing press given a basic description?

pic versus macro in TikZ

How to know if a folder is a symbolic link?

How to illustrate the Mean Value theorem?

What is the environment variable XDG_VTNR?

Why do Ryanair allow me to book connecting itineraries through a third party, but not through their own website?

Is it true that cut time means "play twice as fast as written"?

Is it possible to build VPN remote access environment without VPN server?

Simple fuzz pedal using breadboard

A steel cutting sword?

Is the field of q-series 'dead'?



How to iterate


in table to find specific text using Protractor?

Locating nearest Button Selenium PythonHow do I find an element that contains specific text in Selenium Webdriver (Python)?How to iterate over the keys and values with ng-repeat in AngularJS?How to getText on an input in protractorHow to find specific html elements, AngularJS, protractorProtractor by.repeater not finding anythingHow to find specific row in ng-table by text [protractor]Protractor: How do I select a Radio Button using 'by.repeater'?Can not enter text in input box using sendkeys or javascript in IE11How to find specific row in ProtractorHow to find a specific child element with Protractor






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I have a dynamic table with 2 columns and n number of rows.In the first column there will be a title and in second column it will be the button to go into details of that title.



I want to iterate through each of the row to find specific text title and click on the second column's button of that title.



I tried many ways searching google but couldn't find anything.



The AngularJS code for that in HTML is as below.



<table>
<tbody>
<tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
<td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test</td>
<td style="padding-left: 20px;">
<button ng-click="enter(registration)" class="ng-binding">Enter community</button>
</td>


<tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
<td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test1</td>
<td style="padding-left: 20px;">
<button ng-click="enter(registration)" class="ng-binding">Enter community</button>
</td>



<tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
<td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test2</td>
<td style="padding-left: 20px;">
<button ng-click="enter(registration)" class="ng-binding">Enter community</button>
</td>
</tbody>
</table>



As shown in the above table there are three rows. I want to select the row by name to suppose "test1" and wants to click on the second column's button of the same row.



Here, I got the index of the specific text I'm looking for by writing below code.



 let elm = element.all(by.repeater('registration in myRegistrations'));
let index;
elm.getText().then(function(text)
console.log(text);
for(var i=0; i<text.length; i++)
if(text[i] == 'protractor-testing Enter community')
index = i;
console.log('Community found :: ' + text[i]);



);

console.log("Index :: " + index);


Now, by this index can I click on the button from the table row = index and second column of the same row?



Below is my whole script.



The conf.js file ..



// An example configuration file
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = ;


Below is my spec.js file



describe('Testing', function()
it('perform login', function()
browser.get(browser.baseUrl);
browser.manage().window().maximize();
console.log("Admin :: " + browser.params.AdminUsername + " " + browser.params.AdminPassword);
element(by.model('user.userName')).sendKeys(browser.params.AdminUsername);
element(by.model('user.password')).sendKeys(browser.params.AdminPassword);
browser.sleep('2000');
element(by.buttonText('Login')).click();
element(by.model("newCommunity.title")).sendKeys(browser.params.CreateTitle);
element(by.model("newCommunity.key")).sendKeys(browser.params.CreateKey);
let buttons = element.all(by.css("button.ng-binding"));
let tds = element.all(by.css("td.ng-binding"));
console.log("Buttons :: " + buttons);
console.log("tds :: " + tds);
// var buttons = driver.findElements(By.css("button.ng-binding"));
// var tds = driver.findElements(By.css("td.ng-binding"));
for (var i = 0; i < tds.length; i++)
console.log("get text for index " + i + " Value :: " + tds[i].getText());
if (tds[i].getText() == 'protractor-testing')
console.log("Got the actual community at : " + i);
console.log("Clicking button :: " + buttons[i]);
buttons[i].click();
break;



);
})


Please note that I do not want to use xPath.










share|improve this question






























    -1















    I have a dynamic table with 2 columns and n number of rows.In the first column there will be a title and in second column it will be the button to go into details of that title.



    I want to iterate through each of the row to find specific text title and click on the second column's button of that title.



    I tried many ways searching google but couldn't find anything.



    The AngularJS code for that in HTML is as below.



    <table>
    <tbody>
    <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
    <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test</td>
    <td style="padding-left: 20px;">
    <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
    </td>


    <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
    <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test1</td>
    <td style="padding-left: 20px;">
    <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
    </td>



    <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
    <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test2</td>
    <td style="padding-left: 20px;">
    <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
    </td>
    </tbody>
    </table>



    As shown in the above table there are three rows. I want to select the row by name to suppose "test1" and wants to click on the second column's button of the same row.



    Here, I got the index of the specific text I'm looking for by writing below code.



     let elm = element.all(by.repeater('registration in myRegistrations'));
    let index;
    elm.getText().then(function(text)
    console.log(text);
    for(var i=0; i<text.length; i++)
    if(text[i] == 'protractor-testing Enter community')
    index = i;
    console.log('Community found :: ' + text[i]);



    );

    console.log("Index :: " + index);


    Now, by this index can I click on the button from the table row = index and second column of the same row?



    Below is my whole script.



    The conf.js file ..



    // An example configuration file
    var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
    exports.config = ;


    Below is my spec.js file



    describe('Testing', function()
    it('perform login', function()
    browser.get(browser.baseUrl);
    browser.manage().window().maximize();
    console.log("Admin :: " + browser.params.AdminUsername + " " + browser.params.AdminPassword);
    element(by.model('user.userName')).sendKeys(browser.params.AdminUsername);
    element(by.model('user.password')).sendKeys(browser.params.AdminPassword);
    browser.sleep('2000');
    element(by.buttonText('Login')).click();
    element(by.model("newCommunity.title")).sendKeys(browser.params.CreateTitle);
    element(by.model("newCommunity.key")).sendKeys(browser.params.CreateKey);
    let buttons = element.all(by.css("button.ng-binding"));
    let tds = element.all(by.css("td.ng-binding"));
    console.log("Buttons :: " + buttons);
    console.log("tds :: " + tds);
    // var buttons = driver.findElements(By.css("button.ng-binding"));
    // var tds = driver.findElements(By.css("td.ng-binding"));
    for (var i = 0; i < tds.length; i++)
    console.log("get text for index " + i + " Value :: " + tds[i].getText());
    if (tds[i].getText() == 'protractor-testing')
    console.log("Got the actual community at : " + i);
    console.log("Clicking button :: " + buttons[i]);
    buttons[i].click();
    break;



    );
    })


    Please note that I do not want to use xPath.










    share|improve this question


























      -1












      -1








      -1








      I have a dynamic table with 2 columns and n number of rows.In the first column there will be a title and in second column it will be the button to go into details of that title.



      I want to iterate through each of the row to find specific text title and click on the second column's button of that title.



      I tried many ways searching google but couldn't find anything.



      The AngularJS code for that in HTML is as below.



      <table>
      <tbody>
      <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
      <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test</td>
      <td style="padding-left: 20px;">
      <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
      </td>


      <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
      <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test1</td>
      <td style="padding-left: 20px;">
      <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
      </td>



      <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
      <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test2</td>
      <td style="padding-left: 20px;">
      <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
      </td>
      </tbody>
      </table>



      As shown in the above table there are three rows. I want to select the row by name to suppose "test1" and wants to click on the second column's button of the same row.



      Here, I got the index of the specific text I'm looking for by writing below code.



       let elm = element.all(by.repeater('registration in myRegistrations'));
      let index;
      elm.getText().then(function(text)
      console.log(text);
      for(var i=0; i<text.length; i++)
      if(text[i] == 'protractor-testing Enter community')
      index = i;
      console.log('Community found :: ' + text[i]);



      );

      console.log("Index :: " + index);


      Now, by this index can I click on the button from the table row = index and second column of the same row?



      Below is my whole script.



      The conf.js file ..



      // An example configuration file
      var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
      exports.config = ;


      Below is my spec.js file



      describe('Testing', function()
      it('perform login', function()
      browser.get(browser.baseUrl);
      browser.manage().window().maximize();
      console.log("Admin :: " + browser.params.AdminUsername + " " + browser.params.AdminPassword);
      element(by.model('user.userName')).sendKeys(browser.params.AdminUsername);
      element(by.model('user.password')).sendKeys(browser.params.AdminPassword);
      browser.sleep('2000');
      element(by.buttonText('Login')).click();
      element(by.model("newCommunity.title")).sendKeys(browser.params.CreateTitle);
      element(by.model("newCommunity.key")).sendKeys(browser.params.CreateKey);
      let buttons = element.all(by.css("button.ng-binding"));
      let tds = element.all(by.css("td.ng-binding"));
      console.log("Buttons :: " + buttons);
      console.log("tds :: " + tds);
      // var buttons = driver.findElements(By.css("button.ng-binding"));
      // var tds = driver.findElements(By.css("td.ng-binding"));
      for (var i = 0; i < tds.length; i++)
      console.log("get text for index " + i + " Value :: " + tds[i].getText());
      if (tds[i].getText() == 'protractor-testing')
      console.log("Got the actual community at : " + i);
      console.log("Clicking button :: " + buttons[i]);
      buttons[i].click();
      break;



      );
      })


      Please note that I do not want to use xPath.










      share|improve this question
















      I have a dynamic table with 2 columns and n number of rows.In the first column there will be a title and in second column it will be the button to go into details of that title.



      I want to iterate through each of the row to find specific text title and click on the second column's button of that title.



      I tried many ways searching google but couldn't find anything.



      The AngularJS code for that in HTML is as below.



      <table>
      <tbody>
      <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
      <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test</td>
      <td style="padding-left: 20px;">
      <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
      </td>


      <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
      <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test1</td>
      <td style="padding-left: 20px;">
      <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
      </td>



      <tr ng-repeat="registration in Registrations | orderBy:'title'" class="tableRow ng-scope">
      <td style="padding-left: 20px;" ng-if="reg.title != 'Jabc'" class="ng-binding ng-scope">test2</td>
      <td style="padding-left: 20px;">
      <button ng-click="enter(registration)" class="ng-binding">Enter community</button>
      </td>
      </tbody>
      </table>



      As shown in the above table there are three rows. I want to select the row by name to suppose "test1" and wants to click on the second column's button of the same row.



      Here, I got the index of the specific text I'm looking for by writing below code.



       let elm = element.all(by.repeater('registration in myRegistrations'));
      let index;
      elm.getText().then(function(text)
      console.log(text);
      for(var i=0; i<text.length; i++)
      if(text[i] == 'protractor-testing Enter community')
      index = i;
      console.log('Community found :: ' + text[i]);



      );

      console.log("Index :: " + index);


      Now, by this index can I click on the button from the table row = index and second column of the same row?



      Below is my whole script.



      The conf.js file ..



      // An example configuration file
      var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
      exports.config = ;


      Below is my spec.js file



      describe('Testing', function()
      it('perform login', function()
      browser.get(browser.baseUrl);
      browser.manage().window().maximize();
      console.log("Admin :: " + browser.params.AdminUsername + " " + browser.params.AdminPassword);
      element(by.model('user.userName')).sendKeys(browser.params.AdminUsername);
      element(by.model('user.password')).sendKeys(browser.params.AdminPassword);
      browser.sleep('2000');
      element(by.buttonText('Login')).click();
      element(by.model("newCommunity.title")).sendKeys(browser.params.CreateTitle);
      element(by.model("newCommunity.key")).sendKeys(browser.params.CreateKey);
      let buttons = element.all(by.css("button.ng-binding"));
      let tds = element.all(by.css("td.ng-binding"));
      console.log("Buttons :: " + buttons);
      console.log("tds :: " + tds);
      // var buttons = driver.findElements(By.css("button.ng-binding"));
      // var tds = driver.findElements(By.css("td.ng-binding"));
      for (var i = 0; i < tds.length; i++)
      console.log("get text for index " + i + " Value :: " + tds[i].getText());
      if (tds[i].getText() == 'protractor-testing')
      console.log("Got the actual community at : " + i);
      console.log("Clicking button :: " + buttons[i]);
      buttons[i].click();
      break;



      );
      })


      Please note that I do not want to use xPath.







      angularjs selenium selenium-webdriver css-selectors protractor






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 15:43







      Virus

















      asked Mar 24 at 5:22









      VirusVirus

      215




      215






















          4 Answers
          4






          active

          oldest

          votes


















          1














          Your requirement not to use xpath seems very restrictive as it is by far the best method for your use case mainly because locating based on css does not allow you to do exact matching on the tag text, in your case the title <td>s.



          To achieve this using css you will have to use some potentially unreliable chained locators such as



          element(by.cssContainingText('tr','test')).element(by.css('button'));


          I say unreliable as this locator will actually identify all three of your buttons due to the fact that all three of your title tag contain the characters 'test'. It works in this case but could cause issue in your actual tests.



          I would seriously recommend pushing back on that no xpath requirement and going with the following sibling answer provided by C Peck as that will be the most reliable long term.






          share|improve this answer

























          • I think you meant to pass ('td','test') into cssContainingText() There is a problem with using cssContainingText(); for example in the code you have above, (after swapping 'td' for 'tr') it will match all three td nodes simply because the strings "test", "test1", and "test2" all contain "test".

            – C. Peck
            Mar 25 at 6:57











          • @C.Peck actually I intended to use tr. By using tr it will look at the text from all the elements that are a child of the tr tag, including the title and button tags. Then we can chain on another locator which can find a child (the button). If we used td we would not be able chain locators as both tds are siblings on the same node. Also I addressed that potential issue with cssContainingText in my answer but wanted to provide a potential solution to OP could try if not using xpath is really an unavoidable constraint.

            – DublinDev
            Mar 25 at 7:28











          • Well, I dunno how I missed that explanation but there it is, oops. Anyhow, regarding cssContainingText what makes you say By using tr it will look at the text from all the elements that are a child of the tr tag? I was looking at the source code and found that cssContainingText just passes its arguments to another function, findByCssContainingText the clientSideScripts file. Here’s what cssContainingText returns: return driver.findElements(By.js( clientSideScripts.findByCssContainingText, cssSelector, searchText, using, rootSelector));

            – C. Peck
            Mar 25 at 8:51











          • Moving on to the clientSideScriptsl file, I found the following in the body of the findByCssContainingText: var elements = using.querySelectorAll(cssSelector); var matches = []; for (var i = 0; i < elements.length; ++i) return matches;

            – C. Peck
            Mar 25 at 9:07












          • @C.Peck I can't point you to the piece of code which is responsible for it but I know from experience that calling some of the the element methods on elements which contain sub-elements will run on all of them. I copied down the html code in the question and run some locators locally and what I saw from running element(by.cssContainingText('tr','test')).getText() was test Enter community

            – DublinDev
            Mar 25 at 9:18


















          1














          Well for one thing I would not personally have elements that are identical (in terms of HTML) on the same page if I can control it. But to get your element on the HTML shown, the following should work:
          (I'm writing Javascript because of your protractor tag I'm assuming that's how your tests are written)



          buttons = driver.findElements(By.xpath("//button"))
          buttons[1].click();


          However, if you want to find it specifically by the name (for any use case) you could do



          buttonWithText1 = driver.findElement(By.xpath("//td[text()[contains(., 'test1')]]/following-sibling::td/button");
          buttonWithText1.click();


          As @Sers points out below the xpath //td[.='test1']/following-sibling::td/button also works and is the cleanest. Or shortest, at least.



          If you want to dynamically use that xpath to find buttons by that text you could use:



          var myText = "test1"
          driver.findElement(By.xpath("//td[.='" + myText + "']/following-sibling::td/button).click()


          EDIT



          the user has said that they don’t want to use xpath. Based on the HTML you could use a css selector like this to select the button next to some string myText.



          var buttons = browser.findElements(By.css(‘button.ng-binding’))
          var tds = browser.findElements(By.css(‘td.ng-binding’))
          for (i = 0; i < tds.length; i++)
          if (tds[i].getText()==myText)
          buttons[i].click()
          break;







          share|improve this answer

























          • Also can be //td[.='test1']/following-sibling::td/button

            – Sers
            Mar 24 at 7:24






          • 1





            i agree axes are the way to go but button is not a sibling of the td that contains the title text. I think you need will need //td[.='test1']/parent::tr[1]//button[1] or else //td[.='test1']/following::button[1]

            – DublinDev
            Mar 24 at 7:30











          • @DublinDev there're a lot way to do it, all depends on the rest HTML. //td[.='test1']/following::button[1] cleanest one

            – Sers
            Mar 24 at 7:32







          • 1





            @DublinDev I think the formatting is a bit funky and they should be siblings (also there's no closing tag on any of the tr elements)

            – C. Peck
            Mar 24 at 8:15











          • Hi @C. Peck, I want to try your code but driver is undefined it says.

            – Virus
            Mar 25 at 13:42


















          -1














          You can use xpath to achieve your goal:



          //tr[contains(@class,'tableRow') and ./td[.='test']]//button


          You can find more examples here.






          share|improve this answer

























          • I'm sorry but I do not want to use xPath.

            – Virus
            Mar 24 at 12:39











          • @Virus why? This is the fastest way to find by text

            – Sers
            Mar 24 at 12:41











          • I know but My requirements are given and they told not to use xPath.

            – Virus
            Mar 24 at 12:57











          • @Sers actually xpath is the slowest way to identify an element, with id being the fastest. here you can find actual performance numbers for xpath and css; css was always faster.

            – C. Peck
            Mar 24 at 13:30












          • @C.Peck for the case, xpath is much faster, than iterate throw each element. Also even I prefer css, actually between xpath and css there’s no critical differences for test purposes.

            – Sers
            Mar 24 at 14:13



















          -1














          You do not want to use xpath and barring the innerHTML all the other attribute values of the reference <td> nodes are identical. Now css-selectors doesn't supports innerHTML, so to locate the button adjacent to the element with text as test1 you can use the following css-selectors:



          "table>tbody tr:nth-child(2) td:nth-child(2)>button"





          share|improve this answer

























          • OP wants to do it dynamically and have a css selector that finds the buttons based on the text of the button’s adjacent label—I already offered a solution like yours but they responded that they want to dynamically search based on the innerHTML of the td. I’m currently writing up a fairly hacky way to accomplish this.

            – C. Peck
            Mar 25 at 9:40











          • I agree with C. Peck.

            – Virus
            Mar 25 at 13:17











          • @DebanjanB beside the point, but if you're going to use that full css selector you'd be better off with driver.findElements(By.css('button'))[1].click(); :)

            – C. Peck
            Mar 25 at 16:17












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320960%2fhow-to-iterate-td-in-table-to-find-specific-text-using-protractor%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Your requirement not to use xpath seems very restrictive as it is by far the best method for your use case mainly because locating based on css does not allow you to do exact matching on the tag text, in your case the title <td>s.



          To achieve this using css you will have to use some potentially unreliable chained locators such as



          element(by.cssContainingText('tr','test')).element(by.css('button'));


          I say unreliable as this locator will actually identify all three of your buttons due to the fact that all three of your title tag contain the characters 'test'. It works in this case but could cause issue in your actual tests.



          I would seriously recommend pushing back on that no xpath requirement and going with the following sibling answer provided by C Peck as that will be the most reliable long term.






          share|improve this answer

























          • I think you meant to pass ('td','test') into cssContainingText() There is a problem with using cssContainingText(); for example in the code you have above, (after swapping 'td' for 'tr') it will match all three td nodes simply because the strings "test", "test1", and "test2" all contain "test".

            – C. Peck
            Mar 25 at 6:57











          • @C.Peck actually I intended to use tr. By using tr it will look at the text from all the elements that are a child of the tr tag, including the title and button tags. Then we can chain on another locator which can find a child (the button). If we used td we would not be able chain locators as both tds are siblings on the same node. Also I addressed that potential issue with cssContainingText in my answer but wanted to provide a potential solution to OP could try if not using xpath is really an unavoidable constraint.

            – DublinDev
            Mar 25 at 7:28











          • Well, I dunno how I missed that explanation but there it is, oops. Anyhow, regarding cssContainingText what makes you say By using tr it will look at the text from all the elements that are a child of the tr tag? I was looking at the source code and found that cssContainingText just passes its arguments to another function, findByCssContainingText the clientSideScripts file. Here’s what cssContainingText returns: return driver.findElements(By.js( clientSideScripts.findByCssContainingText, cssSelector, searchText, using, rootSelector));

            – C. Peck
            Mar 25 at 8:51











          • Moving on to the clientSideScriptsl file, I found the following in the body of the findByCssContainingText: var elements = using.querySelectorAll(cssSelector); var matches = []; for (var i = 0; i < elements.length; ++i) return matches;

            – C. Peck
            Mar 25 at 9:07












          • @C.Peck I can't point you to the piece of code which is responsible for it but I know from experience that calling some of the the element methods on elements which contain sub-elements will run on all of them. I copied down the html code in the question and run some locators locally and what I saw from running element(by.cssContainingText('tr','test')).getText() was test Enter community

            – DublinDev
            Mar 25 at 9:18















          1














          Your requirement not to use xpath seems very restrictive as it is by far the best method for your use case mainly because locating based on css does not allow you to do exact matching on the tag text, in your case the title <td>s.



          To achieve this using css you will have to use some potentially unreliable chained locators such as



          element(by.cssContainingText('tr','test')).element(by.css('button'));


          I say unreliable as this locator will actually identify all three of your buttons due to the fact that all three of your title tag contain the characters 'test'. It works in this case but could cause issue in your actual tests.



          I would seriously recommend pushing back on that no xpath requirement and going with the following sibling answer provided by C Peck as that will be the most reliable long term.






          share|improve this answer

























          • I think you meant to pass ('td','test') into cssContainingText() There is a problem with using cssContainingText(); for example in the code you have above, (after swapping 'td' for 'tr') it will match all three td nodes simply because the strings "test", "test1", and "test2" all contain "test".

            – C. Peck
            Mar 25 at 6:57











          • @C.Peck actually I intended to use tr. By using tr it will look at the text from all the elements that are a child of the tr tag, including the title and button tags. Then we can chain on another locator which can find a child (the button). If we used td we would not be able chain locators as both tds are siblings on the same node. Also I addressed that potential issue with cssContainingText in my answer but wanted to provide a potential solution to OP could try if not using xpath is really an unavoidable constraint.

            – DublinDev
            Mar 25 at 7:28











          • Well, I dunno how I missed that explanation but there it is, oops. Anyhow, regarding cssContainingText what makes you say By using tr it will look at the text from all the elements that are a child of the tr tag? I was looking at the source code and found that cssContainingText just passes its arguments to another function, findByCssContainingText the clientSideScripts file. Here’s what cssContainingText returns: return driver.findElements(By.js( clientSideScripts.findByCssContainingText, cssSelector, searchText, using, rootSelector));

            – C. Peck
            Mar 25 at 8:51











          • Moving on to the clientSideScriptsl file, I found the following in the body of the findByCssContainingText: var elements = using.querySelectorAll(cssSelector); var matches = []; for (var i = 0; i < elements.length; ++i) return matches;

            – C. Peck
            Mar 25 at 9:07












          • @C.Peck I can't point you to the piece of code which is responsible for it but I know from experience that calling some of the the element methods on elements which contain sub-elements will run on all of them. I copied down the html code in the question and run some locators locally and what I saw from running element(by.cssContainingText('tr','test')).getText() was test Enter community

            – DublinDev
            Mar 25 at 9:18













          1












          1








          1







          Your requirement not to use xpath seems very restrictive as it is by far the best method for your use case mainly because locating based on css does not allow you to do exact matching on the tag text, in your case the title <td>s.



          To achieve this using css you will have to use some potentially unreliable chained locators such as



          element(by.cssContainingText('tr','test')).element(by.css('button'));


          I say unreliable as this locator will actually identify all three of your buttons due to the fact that all three of your title tag contain the characters 'test'. It works in this case but could cause issue in your actual tests.



          I would seriously recommend pushing back on that no xpath requirement and going with the following sibling answer provided by C Peck as that will be the most reliable long term.






          share|improve this answer















          Your requirement not to use xpath seems very restrictive as it is by far the best method for your use case mainly because locating based on css does not allow you to do exact matching on the tag text, in your case the title <td>s.



          To achieve this using css you will have to use some potentially unreliable chained locators such as



          element(by.cssContainingText('tr','test')).element(by.css('button'));


          I say unreliable as this locator will actually identify all three of your buttons due to the fact that all three of your title tag contain the characters 'test'. It works in this case but could cause issue in your actual tests.



          I would seriously recommend pushing back on that no xpath requirement and going with the following sibling answer provided by C Peck as that will be the most reliable long term.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 24 at 22:17

























          answered Mar 24 at 21:45









          DublinDevDublinDev

          1,2382321




          1,2382321












          • I think you meant to pass ('td','test') into cssContainingText() There is a problem with using cssContainingText(); for example in the code you have above, (after swapping 'td' for 'tr') it will match all three td nodes simply because the strings "test", "test1", and "test2" all contain "test".

            – C. Peck
            Mar 25 at 6:57











          • @C.Peck actually I intended to use tr. By using tr it will look at the text from all the elements that are a child of the tr tag, including the title and button tags. Then we can chain on another locator which can find a child (the button). If we used td we would not be able chain locators as both tds are siblings on the same node. Also I addressed that potential issue with cssContainingText in my answer but wanted to provide a potential solution to OP could try if not using xpath is really an unavoidable constraint.

            – DublinDev
            Mar 25 at 7:28











          • Well, I dunno how I missed that explanation but there it is, oops. Anyhow, regarding cssContainingText what makes you say By using tr it will look at the text from all the elements that are a child of the tr tag? I was looking at the source code and found that cssContainingText just passes its arguments to another function, findByCssContainingText the clientSideScripts file. Here’s what cssContainingText returns: return driver.findElements(By.js( clientSideScripts.findByCssContainingText, cssSelector, searchText, using, rootSelector));

            – C. Peck
            Mar 25 at 8:51











          • Moving on to the clientSideScriptsl file, I found the following in the body of the findByCssContainingText: var elements = using.querySelectorAll(cssSelector); var matches = []; for (var i = 0; i < elements.length; ++i) return matches;

            – C. Peck
            Mar 25 at 9:07












          • @C.Peck I can't point you to the piece of code which is responsible for it but I know from experience that calling some of the the element methods on elements which contain sub-elements will run on all of them. I copied down the html code in the question and run some locators locally and what I saw from running element(by.cssContainingText('tr','test')).getText() was test Enter community

            – DublinDev
            Mar 25 at 9:18

















          • I think you meant to pass ('td','test') into cssContainingText() There is a problem with using cssContainingText(); for example in the code you have above, (after swapping 'td' for 'tr') it will match all three td nodes simply because the strings "test", "test1", and "test2" all contain "test".

            – C. Peck
            Mar 25 at 6:57











          • @C.Peck actually I intended to use tr. By using tr it will look at the text from all the elements that are a child of the tr tag, including the title and button tags. Then we can chain on another locator which can find a child (the button). If we used td we would not be able chain locators as both tds are siblings on the same node. Also I addressed that potential issue with cssContainingText in my answer but wanted to provide a potential solution to OP could try if not using xpath is really an unavoidable constraint.

            – DublinDev
            Mar 25 at 7:28











          • Well, I dunno how I missed that explanation but there it is, oops. Anyhow, regarding cssContainingText what makes you say By using tr it will look at the text from all the elements that are a child of the tr tag? I was looking at the source code and found that cssContainingText just passes its arguments to another function, findByCssContainingText the clientSideScripts file. Here’s what cssContainingText returns: return driver.findElements(By.js( clientSideScripts.findByCssContainingText, cssSelector, searchText, using, rootSelector));

            – C. Peck
            Mar 25 at 8:51











          • Moving on to the clientSideScriptsl file, I found the following in the body of the findByCssContainingText: var elements = using.querySelectorAll(cssSelector); var matches = []; for (var i = 0; i < elements.length; ++i) return matches;

            – C. Peck
            Mar 25 at 9:07












          • @C.Peck I can't point you to the piece of code which is responsible for it but I know from experience that calling some of the the element methods on elements which contain sub-elements will run on all of them. I copied down the html code in the question and run some locators locally and what I saw from running element(by.cssContainingText('tr','test')).getText() was test Enter community

            – DublinDev
            Mar 25 at 9:18
















          I think you meant to pass ('td','test') into cssContainingText() There is a problem with using cssContainingText(); for example in the code you have above, (after swapping 'td' for 'tr') it will match all three td nodes simply because the strings "test", "test1", and "test2" all contain "test".

          – C. Peck
          Mar 25 at 6:57





          I think you meant to pass ('td','test') into cssContainingText() There is a problem with using cssContainingText(); for example in the code you have above, (after swapping 'td' for 'tr') it will match all three td nodes simply because the strings "test", "test1", and "test2" all contain "test".

          – C. Peck
          Mar 25 at 6:57













          @C.Peck actually I intended to use tr. By using tr it will look at the text from all the elements that are a child of the tr tag, including the title and button tags. Then we can chain on another locator which can find a child (the button). If we used td we would not be able chain locators as both tds are siblings on the same node. Also I addressed that potential issue with cssContainingText in my answer but wanted to provide a potential solution to OP could try if not using xpath is really an unavoidable constraint.

          – DublinDev
          Mar 25 at 7:28





          @C.Peck actually I intended to use tr. By using tr it will look at the text from all the elements that are a child of the tr tag, including the title and button tags. Then we can chain on another locator which can find a child (the button). If we used td we would not be able chain locators as both tds are siblings on the same node. Also I addressed that potential issue with cssContainingText in my answer but wanted to provide a potential solution to OP could try if not using xpath is really an unavoidable constraint.

          – DublinDev
          Mar 25 at 7:28













          Well, I dunno how I missed that explanation but there it is, oops. Anyhow, regarding cssContainingText what makes you say By using tr it will look at the text from all the elements that are a child of the tr tag? I was looking at the source code and found that cssContainingText just passes its arguments to another function, findByCssContainingText the clientSideScripts file. Here’s what cssContainingText returns: return driver.findElements(By.js( clientSideScripts.findByCssContainingText, cssSelector, searchText, using, rootSelector));

          – C. Peck
          Mar 25 at 8:51





          Well, I dunno how I missed that explanation but there it is, oops. Anyhow, regarding cssContainingText what makes you say By using tr it will look at the text from all the elements that are a child of the tr tag? I was looking at the source code and found that cssContainingText just passes its arguments to another function, findByCssContainingText the clientSideScripts file. Here’s what cssContainingText returns: return driver.findElements(By.js( clientSideScripts.findByCssContainingText, cssSelector, searchText, using, rootSelector));

          – C. Peck
          Mar 25 at 8:51













          Moving on to the clientSideScriptsl file, I found the following in the body of the findByCssContainingText: var elements = using.querySelectorAll(cssSelector); var matches = []; for (var i = 0; i < elements.length; ++i) return matches;

          – C. Peck
          Mar 25 at 9:07






          Moving on to the clientSideScriptsl file, I found the following in the body of the findByCssContainingText: var elements = using.querySelectorAll(cssSelector); var matches = []; for (var i = 0; i < elements.length; ++i) return matches;

          – C. Peck
          Mar 25 at 9:07














          @C.Peck I can't point you to the piece of code which is responsible for it but I know from experience that calling some of the the element methods on elements which contain sub-elements will run on all of them. I copied down the html code in the question and run some locators locally and what I saw from running element(by.cssContainingText('tr','test')).getText() was test Enter community

          – DublinDev
          Mar 25 at 9:18





          @C.Peck I can't point you to the piece of code which is responsible for it but I know from experience that calling some of the the element methods on elements which contain sub-elements will run on all of them. I copied down the html code in the question and run some locators locally and what I saw from running element(by.cssContainingText('tr','test')).getText() was test Enter community

          – DublinDev
          Mar 25 at 9:18













          1














          Well for one thing I would not personally have elements that are identical (in terms of HTML) on the same page if I can control it. But to get your element on the HTML shown, the following should work:
          (I'm writing Javascript because of your protractor tag I'm assuming that's how your tests are written)



          buttons = driver.findElements(By.xpath("//button"))
          buttons[1].click();


          However, if you want to find it specifically by the name (for any use case) you could do



          buttonWithText1 = driver.findElement(By.xpath("//td[text()[contains(., 'test1')]]/following-sibling::td/button");
          buttonWithText1.click();


          As @Sers points out below the xpath //td[.='test1']/following-sibling::td/button also works and is the cleanest. Or shortest, at least.



          If you want to dynamically use that xpath to find buttons by that text you could use:



          var myText = "test1"
          driver.findElement(By.xpath("//td[.='" + myText + "']/following-sibling::td/button).click()


          EDIT



          the user has said that they don’t want to use xpath. Based on the HTML you could use a css selector like this to select the button next to some string myText.



          var buttons = browser.findElements(By.css(‘button.ng-binding’))
          var tds = browser.findElements(By.css(‘td.ng-binding’))
          for (i = 0; i < tds.length; i++)
          if (tds[i].getText()==myText)
          buttons[i].click()
          break;







          share|improve this answer

























          • Also can be //td[.='test1']/following-sibling::td/button

            – Sers
            Mar 24 at 7:24






          • 1





            i agree axes are the way to go but button is not a sibling of the td that contains the title text. I think you need will need //td[.='test1']/parent::tr[1]//button[1] or else //td[.='test1']/following::button[1]

            – DublinDev
            Mar 24 at 7:30











          • @DublinDev there're a lot way to do it, all depends on the rest HTML. //td[.='test1']/following::button[1] cleanest one

            – Sers
            Mar 24 at 7:32







          • 1





            @DublinDev I think the formatting is a bit funky and they should be siblings (also there's no closing tag on any of the tr elements)

            – C. Peck
            Mar 24 at 8:15











          • Hi @C. Peck, I want to try your code but driver is undefined it says.

            – Virus
            Mar 25 at 13:42















          1














          Well for one thing I would not personally have elements that are identical (in terms of HTML) on the same page if I can control it. But to get your element on the HTML shown, the following should work:
          (I'm writing Javascript because of your protractor tag I'm assuming that's how your tests are written)



          buttons = driver.findElements(By.xpath("//button"))
          buttons[1].click();


          However, if you want to find it specifically by the name (for any use case) you could do



          buttonWithText1 = driver.findElement(By.xpath("//td[text()[contains(., 'test1')]]/following-sibling::td/button");
          buttonWithText1.click();


          As @Sers points out below the xpath //td[.='test1']/following-sibling::td/button also works and is the cleanest. Or shortest, at least.



          If you want to dynamically use that xpath to find buttons by that text you could use:



          var myText = "test1"
          driver.findElement(By.xpath("//td[.='" + myText + "']/following-sibling::td/button).click()


          EDIT



          the user has said that they don’t want to use xpath. Based on the HTML you could use a css selector like this to select the button next to some string myText.



          var buttons = browser.findElements(By.css(‘button.ng-binding’))
          var tds = browser.findElements(By.css(‘td.ng-binding’))
          for (i = 0; i < tds.length; i++)
          if (tds[i].getText()==myText)
          buttons[i].click()
          break;







          share|improve this answer

























          • Also can be //td[.='test1']/following-sibling::td/button

            – Sers
            Mar 24 at 7:24






          • 1





            i agree axes are the way to go but button is not a sibling of the td that contains the title text. I think you need will need //td[.='test1']/parent::tr[1]//button[1] or else //td[.='test1']/following::button[1]

            – DublinDev
            Mar 24 at 7:30











          • @DublinDev there're a lot way to do it, all depends on the rest HTML. //td[.='test1']/following::button[1] cleanest one

            – Sers
            Mar 24 at 7:32







          • 1





            @DublinDev I think the formatting is a bit funky and they should be siblings (also there's no closing tag on any of the tr elements)

            – C. Peck
            Mar 24 at 8:15











          • Hi @C. Peck, I want to try your code but driver is undefined it says.

            – Virus
            Mar 25 at 13:42













          1












          1








          1







          Well for one thing I would not personally have elements that are identical (in terms of HTML) on the same page if I can control it. But to get your element on the HTML shown, the following should work:
          (I'm writing Javascript because of your protractor tag I'm assuming that's how your tests are written)



          buttons = driver.findElements(By.xpath("//button"))
          buttons[1].click();


          However, if you want to find it specifically by the name (for any use case) you could do



          buttonWithText1 = driver.findElement(By.xpath("//td[text()[contains(., 'test1')]]/following-sibling::td/button");
          buttonWithText1.click();


          As @Sers points out below the xpath //td[.='test1']/following-sibling::td/button also works and is the cleanest. Or shortest, at least.



          If you want to dynamically use that xpath to find buttons by that text you could use:



          var myText = "test1"
          driver.findElement(By.xpath("//td[.='" + myText + "']/following-sibling::td/button).click()


          EDIT



          the user has said that they don’t want to use xpath. Based on the HTML you could use a css selector like this to select the button next to some string myText.



          var buttons = browser.findElements(By.css(‘button.ng-binding’))
          var tds = browser.findElements(By.css(‘td.ng-binding’))
          for (i = 0; i < tds.length; i++)
          if (tds[i].getText()==myText)
          buttons[i].click()
          break;







          share|improve this answer















          Well for one thing I would not personally have elements that are identical (in terms of HTML) on the same page if I can control it. But to get your element on the HTML shown, the following should work:
          (I'm writing Javascript because of your protractor tag I'm assuming that's how your tests are written)



          buttons = driver.findElements(By.xpath("//button"))
          buttons[1].click();


          However, if you want to find it specifically by the name (for any use case) you could do



          buttonWithText1 = driver.findElement(By.xpath("//td[text()[contains(., 'test1')]]/following-sibling::td/button");
          buttonWithText1.click();


          As @Sers points out below the xpath //td[.='test1']/following-sibling::td/button also works and is the cleanest. Or shortest, at least.



          If you want to dynamically use that xpath to find buttons by that text you could use:



          var myText = "test1"
          driver.findElement(By.xpath("//td[.='" + myText + "']/following-sibling::td/button).click()


          EDIT



          the user has said that they don’t want to use xpath. Based on the HTML you could use a css selector like this to select the button next to some string myText.



          var buttons = browser.findElements(By.css(‘button.ng-binding’))
          var tds = browser.findElements(By.css(‘td.ng-binding’))
          for (i = 0; i < tds.length; i++)
          if (tds[i].getText()==myText)
          buttons[i].click()
          break;








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 25 at 15:56

























          answered Mar 24 at 7:13









          C. PeckC. Peck

          960324




          960324












          • Also can be //td[.='test1']/following-sibling::td/button

            – Sers
            Mar 24 at 7:24






          • 1





            i agree axes are the way to go but button is not a sibling of the td that contains the title text. I think you need will need //td[.='test1']/parent::tr[1]//button[1] or else //td[.='test1']/following::button[1]

            – DublinDev
            Mar 24 at 7:30











          • @DublinDev there're a lot way to do it, all depends on the rest HTML. //td[.='test1']/following::button[1] cleanest one

            – Sers
            Mar 24 at 7:32







          • 1





            @DublinDev I think the formatting is a bit funky and they should be siblings (also there's no closing tag on any of the tr elements)

            – C. Peck
            Mar 24 at 8:15











          • Hi @C. Peck, I want to try your code but driver is undefined it says.

            – Virus
            Mar 25 at 13:42

















          • Also can be //td[.='test1']/following-sibling::td/button

            – Sers
            Mar 24 at 7:24






          • 1





            i agree axes are the way to go but button is not a sibling of the td that contains the title text. I think you need will need //td[.='test1']/parent::tr[1]//button[1] or else //td[.='test1']/following::button[1]

            – DublinDev
            Mar 24 at 7:30











          • @DublinDev there're a lot way to do it, all depends on the rest HTML. //td[.='test1']/following::button[1] cleanest one

            – Sers
            Mar 24 at 7:32







          • 1





            @DublinDev I think the formatting is a bit funky and they should be siblings (also there's no closing tag on any of the tr elements)

            – C. Peck
            Mar 24 at 8:15











          • Hi @C. Peck, I want to try your code but driver is undefined it says.

            – Virus
            Mar 25 at 13:42
















          Also can be //td[.='test1']/following-sibling::td/button

          – Sers
          Mar 24 at 7:24





          Also can be //td[.='test1']/following-sibling::td/button

          – Sers
          Mar 24 at 7:24




          1




          1





          i agree axes are the way to go but button is not a sibling of the td that contains the title text. I think you need will need //td[.='test1']/parent::tr[1]//button[1] or else //td[.='test1']/following::button[1]

          – DublinDev
          Mar 24 at 7:30





          i agree axes are the way to go but button is not a sibling of the td that contains the title text. I think you need will need //td[.='test1']/parent::tr[1]//button[1] or else //td[.='test1']/following::button[1]

          – DublinDev
          Mar 24 at 7:30













          @DublinDev there're a lot way to do it, all depends on the rest HTML. //td[.='test1']/following::button[1] cleanest one

          – Sers
          Mar 24 at 7:32






          @DublinDev there're a lot way to do it, all depends on the rest HTML. //td[.='test1']/following::button[1] cleanest one

          – Sers
          Mar 24 at 7:32





          1




          1





          @DublinDev I think the formatting is a bit funky and they should be siblings (also there's no closing tag on any of the tr elements)

          – C. Peck
          Mar 24 at 8:15





          @DublinDev I think the formatting is a bit funky and they should be siblings (also there's no closing tag on any of the tr elements)

          – C. Peck
          Mar 24 at 8:15













          Hi @C. Peck, I want to try your code but driver is undefined it says.

          – Virus
          Mar 25 at 13:42





          Hi @C. Peck, I want to try your code but driver is undefined it says.

          – Virus
          Mar 25 at 13:42











          -1














          You can use xpath to achieve your goal:



          //tr[contains(@class,'tableRow') and ./td[.='test']]//button


          You can find more examples here.






          share|improve this answer

























          • I'm sorry but I do not want to use xPath.

            – Virus
            Mar 24 at 12:39











          • @Virus why? This is the fastest way to find by text

            – Sers
            Mar 24 at 12:41











          • I know but My requirements are given and they told not to use xPath.

            – Virus
            Mar 24 at 12:57











          • @Sers actually xpath is the slowest way to identify an element, with id being the fastest. here you can find actual performance numbers for xpath and css; css was always faster.

            – C. Peck
            Mar 24 at 13:30












          • @C.Peck for the case, xpath is much faster, than iterate throw each element. Also even I prefer css, actually between xpath and css there’s no critical differences for test purposes.

            – Sers
            Mar 24 at 14:13
















          -1














          You can use xpath to achieve your goal:



          //tr[contains(@class,'tableRow') and ./td[.='test']]//button


          You can find more examples here.






          share|improve this answer

























          • I'm sorry but I do not want to use xPath.

            – Virus
            Mar 24 at 12:39











          • @Virus why? This is the fastest way to find by text

            – Sers
            Mar 24 at 12:41











          • I know but My requirements are given and they told not to use xPath.

            – Virus
            Mar 24 at 12:57











          • @Sers actually xpath is the slowest way to identify an element, with id being the fastest. here you can find actual performance numbers for xpath and css; css was always faster.

            – C. Peck
            Mar 24 at 13:30












          • @C.Peck for the case, xpath is much faster, than iterate throw each element. Also even I prefer css, actually between xpath and css there’s no critical differences for test purposes.

            – Sers
            Mar 24 at 14:13














          -1












          -1








          -1







          You can use xpath to achieve your goal:



          //tr[contains(@class,'tableRow') and ./td[.='test']]//button


          You can find more examples here.






          share|improve this answer















          You can use xpath to achieve your goal:



          //tr[contains(@class,'tableRow') and ./td[.='test']]//button


          You can find more examples here.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 24 at 7:22

























          answered Mar 24 at 7:13









          SersSers

          3,3402320




          3,3402320












          • I'm sorry but I do not want to use xPath.

            – Virus
            Mar 24 at 12:39











          • @Virus why? This is the fastest way to find by text

            – Sers
            Mar 24 at 12:41











          • I know but My requirements are given and they told not to use xPath.

            – Virus
            Mar 24 at 12:57











          • @Sers actually xpath is the slowest way to identify an element, with id being the fastest. here you can find actual performance numbers for xpath and css; css was always faster.

            – C. Peck
            Mar 24 at 13:30












          • @C.Peck for the case, xpath is much faster, than iterate throw each element. Also even I prefer css, actually between xpath and css there’s no critical differences for test purposes.

            – Sers
            Mar 24 at 14:13


















          • I'm sorry but I do not want to use xPath.

            – Virus
            Mar 24 at 12:39











          • @Virus why? This is the fastest way to find by text

            – Sers
            Mar 24 at 12:41











          • I know but My requirements are given and they told not to use xPath.

            – Virus
            Mar 24 at 12:57











          • @Sers actually xpath is the slowest way to identify an element, with id being the fastest. here you can find actual performance numbers for xpath and css; css was always faster.

            – C. Peck
            Mar 24 at 13:30












          • @C.Peck for the case, xpath is much faster, than iterate throw each element. Also even I prefer css, actually between xpath and css there’s no critical differences for test purposes.

            – Sers
            Mar 24 at 14:13

















          I'm sorry but I do not want to use xPath.

          – Virus
          Mar 24 at 12:39





          I'm sorry but I do not want to use xPath.

          – Virus
          Mar 24 at 12:39













          @Virus why? This is the fastest way to find by text

          – Sers
          Mar 24 at 12:41





          @Virus why? This is the fastest way to find by text

          – Sers
          Mar 24 at 12:41













          I know but My requirements are given and they told not to use xPath.

          – Virus
          Mar 24 at 12:57





          I know but My requirements are given and they told not to use xPath.

          – Virus
          Mar 24 at 12:57













          @Sers actually xpath is the slowest way to identify an element, with id being the fastest. here you can find actual performance numbers for xpath and css; css was always faster.

          – C. Peck
          Mar 24 at 13:30






          @Sers actually xpath is the slowest way to identify an element, with id being the fastest. here you can find actual performance numbers for xpath and css; css was always faster.

          – C. Peck
          Mar 24 at 13:30














          @C.Peck for the case, xpath is much faster, than iterate throw each element. Also even I prefer css, actually between xpath and css there’s no critical differences for test purposes.

          – Sers
          Mar 24 at 14:13






          @C.Peck for the case, xpath is much faster, than iterate throw each element. Also even I prefer css, actually between xpath and css there’s no critical differences for test purposes.

          – Sers
          Mar 24 at 14:13












          -1














          You do not want to use xpath and barring the innerHTML all the other attribute values of the reference <td> nodes are identical. Now css-selectors doesn't supports innerHTML, so to locate the button adjacent to the element with text as test1 you can use the following css-selectors:



          "table>tbody tr:nth-child(2) td:nth-child(2)>button"





          share|improve this answer

























          • OP wants to do it dynamically and have a css selector that finds the buttons based on the text of the button’s adjacent label—I already offered a solution like yours but they responded that they want to dynamically search based on the innerHTML of the td. I’m currently writing up a fairly hacky way to accomplish this.

            – C. Peck
            Mar 25 at 9:40











          • I agree with C. Peck.

            – Virus
            Mar 25 at 13:17











          • @DebanjanB beside the point, but if you're going to use that full css selector you'd be better off with driver.findElements(By.css('button'))[1].click(); :)

            – C. Peck
            Mar 25 at 16:17
















          -1














          You do not want to use xpath and barring the innerHTML all the other attribute values of the reference <td> nodes are identical. Now css-selectors doesn't supports innerHTML, so to locate the button adjacent to the element with text as test1 you can use the following css-selectors:



          "table>tbody tr:nth-child(2) td:nth-child(2)>button"





          share|improve this answer

























          • OP wants to do it dynamically and have a css selector that finds the buttons based on the text of the button’s adjacent label—I already offered a solution like yours but they responded that they want to dynamically search based on the innerHTML of the td. I’m currently writing up a fairly hacky way to accomplish this.

            – C. Peck
            Mar 25 at 9:40











          • I agree with C. Peck.

            – Virus
            Mar 25 at 13:17











          • @DebanjanB beside the point, but if you're going to use that full css selector you'd be better off with driver.findElements(By.css('button'))[1].click(); :)

            – C. Peck
            Mar 25 at 16:17














          -1












          -1








          -1







          You do not want to use xpath and barring the innerHTML all the other attribute values of the reference <td> nodes are identical. Now css-selectors doesn't supports innerHTML, so to locate the button adjacent to the element with text as test1 you can use the following css-selectors:



          "table>tbody tr:nth-child(2) td:nth-child(2)>button"





          share|improve this answer















          You do not want to use xpath and barring the innerHTML all the other attribute values of the reference <td> nodes are identical. Now css-selectors doesn't supports innerHTML, so to locate the button adjacent to the element with text as test1 you can use the following css-selectors:



          "table>tbody tr:nth-child(2) td:nth-child(2)>button"






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 25 at 9:55

























          answered Mar 25 at 9:30









          DebanjanBDebanjanB

          50.2k144997




          50.2k144997












          • OP wants to do it dynamically and have a css selector that finds the buttons based on the text of the button’s adjacent label—I already offered a solution like yours but they responded that they want to dynamically search based on the innerHTML of the td. I’m currently writing up a fairly hacky way to accomplish this.

            – C. Peck
            Mar 25 at 9:40











          • I agree with C. Peck.

            – Virus
            Mar 25 at 13:17











          • @DebanjanB beside the point, but if you're going to use that full css selector you'd be better off with driver.findElements(By.css('button'))[1].click(); :)

            – C. Peck
            Mar 25 at 16:17


















          • OP wants to do it dynamically and have a css selector that finds the buttons based on the text of the button’s adjacent label—I already offered a solution like yours but they responded that they want to dynamically search based on the innerHTML of the td. I’m currently writing up a fairly hacky way to accomplish this.

            – C. Peck
            Mar 25 at 9:40











          • I agree with C. Peck.

            – Virus
            Mar 25 at 13:17











          • @DebanjanB beside the point, but if you're going to use that full css selector you'd be better off with driver.findElements(By.css('button'))[1].click(); :)

            – C. Peck
            Mar 25 at 16:17

















          OP wants to do it dynamically and have a css selector that finds the buttons based on the text of the button’s adjacent label—I already offered a solution like yours but they responded that they want to dynamically search based on the innerHTML of the td. I’m currently writing up a fairly hacky way to accomplish this.

          – C. Peck
          Mar 25 at 9:40





          OP wants to do it dynamically and have a css selector that finds the buttons based on the text of the button’s adjacent label—I already offered a solution like yours but they responded that they want to dynamically search based on the innerHTML of the td. I’m currently writing up a fairly hacky way to accomplish this.

          – C. Peck
          Mar 25 at 9:40













          I agree with C. Peck.

          – Virus
          Mar 25 at 13:17





          I agree with C. Peck.

          – Virus
          Mar 25 at 13:17













          @DebanjanB beside the point, but if you're going to use that full css selector you'd be better off with driver.findElements(By.css('button'))[1].click(); :)

          – C. Peck
          Mar 25 at 16:17






          @DebanjanB beside the point, but if you're going to use that full css selector you'd be better off with driver.findElements(By.css('button'))[1].click(); :)

          – C. Peck
          Mar 25 at 16:17


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320960%2fhow-to-iterate-td-in-table-to-find-specific-text-using-protractor%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown








          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript