Puppeteer js query and click a link inside of a td where td id contains

Viewed 373

I have to get the following selector. There's several of them:

<td id="content_gvNewLeads_tccell0_5" class="dxgv dx-ellipsis" align="left" style="border-bottom-width:0px;">
                                    <a onclick="return ShowCallDialog(494038, 7);">2 Cloister Court </a>
                                </td>

I'm using puppeteer-select which allows me to use sizzle

  await select(page).assertElementPresent('td.Id:contains(content_gvNewLeads_tccel) > a');
  const element = await select(page).getElement('td.Id:contains(content_gvNewLeads_tccel) > a');
  await element.click()

The error I get is:

Error: an element with selector: "td.Id:contains(content_gvNewLeads_tccel) > a" not found

Any idea how to accomplish this?

1 Answers

There are multiple ways for doing so ..
1. Using simple concept of javascript

 let clickButton = await page.evaluate(()=>{
      let node = document.querySelectorAll('#content_gvNewLeads_tccell0_5 a');
      if(node &&  node.length){ // condition is not much required but still checked
           node[0].click();
           return true;
      }else{
        return false;
      }  
 });
  1. Using concept of selector
       await page.waitForSelector('#content_gvNewLeads_tccell0_5 a');
       await page.click('#content_gvNewLeads_tccell0_5 a');
Related