-1

I am using selenium webdriver to automate a process to update call records in a CRM. During the process, I am finding and selecting elements to click on the webpage. My problem arises when I search the CRM for the client name, the client record returns to the screen but no matter what driver.findElement() I use, I cannot click on the users profile. Can someone please let me know why this is occuring? I have tried a few of the following methods:

driver.findElement(By.xpath("//*[@id=\"Leads_3461487000072987016\"]")).click();

OR

driver.findElement(By.xpath("/html/body/div[66]/div/div[2]/div/div[1]/div[1]/table[2]/tbody/tr/td/table/tbody/tr[2]/td[6]/a")).click();

I thought the element might be on a different iframe but after inspection, I don't believe that it is.

Image of the webpage CRM / Black boxes where user data is returned

The table on the webpage based off the inspection is as follows:

<table width="100%" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="newtable topband_bb" id="gsearchTable"><tbody id="header_Leads">  <tr><th width="0" class="pL0 pR0"></th> <th nowrap=""> Company</th><th nowrap=""> Lead Source</th><th nowrap=""> Phone</th><th nowrap=""> Email</th><th nowrap=""> Full Name</th><th nowrap=""> Lead Owner</th></tr><script x-murphy-load-start="1607451890448">var jarr = [{"PHONE":"8502215904","SEID":"3461487000072987016","EMAIL":"chorton383&#x40;gmail.com","SMOWNERID":"<a id='gsearch_Salutation,First Name,Last Name' class=\"link\" data-cid='usersPermi_viewUser' purpose='showUserBC' data-params='{\"userId\":\"Salutation,First Name,Last Name\"}' >My User Name<\/a>","ISAPPROVED":1,"FULLNAME":"<a id='gsearch_3461487000072987016' href=\"/crm/org673229384/EntityInfo.do?id=3461487000072987016&module=Leads\" data-zcqa=\"gSearch_User name\" data-cid='detailView' data-params='{\"module\":\"Leads\",\"pfrom\":\"gsearch\",\"lookback\":true,\"id\":\"3461487000072987016\",\"recordNum\":\"1\"}' class=\"link\">User Name<\/a>"}];   
var obtained_module = "Leads";
crmNavig.assignNavigCacheData("gsearch", obtained_module, 1, 10 ,jarr);//No I18N
var source   = $('#tmpl_Leads').html();
var template_source = Handlebars.compile(source);
$("#header_Leads").append(template_source(jarr));
</script>
<tr class="topband_dv_row" id="Leads_3461487000072987016">

<td nowrap="" class="pR pL0 pR0"> <div id="icon_3461487000072987016" class="alignright pA w40 mainActionIcon" onclick="sE(event)"><link-to lt-prop-route="crm.tab.module.entity.edit" lt-prop-id="gsearchEdit_3461487000072987016" lt-prop-dp="[&quot;Leads&quot;,&quot;3461487000072987016&quot;]" lt-prop-class="link neweditIcon dIB" data-zcqa="gSearchEditIcon" lt-prop-td="{&quot;recordNum&quot;:&quot;&quot; }" lyte-rendered=""><a id="gsearchEdit_3461487000072987016" class="link neweditIcon dIB" href="/crm/org673229384/tab/Leads/3461487000072987016/edit"></a></link-to>
<a class="mL5 link deleteIcon  dIB" data-params="{&quot;module&quot;:&quot;Leads&quot;}" data-zcqa="gSearchDeleteIcon" href="javascript:;" onclick="showDeletePopup('gsearch_3461487000072987016', 'crm.button.move.to.trash', '', '', this, true);" data-onclick="javascript:searchDelAction(&quot;/crm/org673229384/MassDelete.do?module=Leads&amp;fromIndex=1&amp;toIndex=10&amp;id=3461487000072987016&amp;type=gsearch&amp;sword=Username\x2BHorton&amp;searchCategory=Leads&amp;userOpt=null&amp;isajax=true&quot;, &quot;Leads&quot;)"></a>
</div>
 </td><td></td> <td></td> <td>8502215904</td> <td>USER_EMAIL</td> <td><a id="gsearch_3461487000072987016" href="/crm/org673229384/EntityInfo.do?id=3461487000072987016&amp;module=Leads" data-zcqa="gSearch_User NAME" data-cid="detailView" data-params="{&quot;module&quot;:&quot;Leads&quot;,&quot;pfrom&quot;:&quot;gsearch&quot;,&quot;lookback&quot;:true,&quot;id&quot;:&quot;3461487000072987016&quot;,&quot;recordNum&quot;:&quot;1&quot;}" class="link">User Name</a></td> <td><a id="gsearch_Salutation,First Name,Last Name" class="link" data-cid="usersPermi_viewUser" purpose="showUserBC" data-params="{&quot;userId&quot;:&quot;Salutation,First Name,Last Name&quot;}">My User Name</a></td> </tr></tbody><script x-murphy-load-start="1607451890448" id="tmpl_Leads" type="text/x-handlebars-template">
{{#each this}}
<tr class="topband_dv_row" id="Leads_{{SEID}}">{{#if ISAPPROVED}}
{{#ifCondLogic ISAPPROVED '!=' 2 '&&' ISAPPROVED '!=' 9}}
{{#ifCondLogic ISAPPROVED '=' '7' '||' ISAPPROVED '=' '8'}}
<td nowrap class="tableData bb" style="vertical-align:middle"> <div align="center" id="icon_{{SEID}}" style="visibility:hidden;"></div><span class="iconlock_ap mL2" title='{{getI18n "crm.reviewprocess.record.review.pending"}}' alt='{{getI18n "crm.reviewprocess.record.review.pending"}}'></span> {{else}}
<td nowrap class="pR pL0 pR0"> <div id="icon_{{SEID}}" class="alignright pA w40 mainActionIcon" onclick="sE(event)"><link-to lt-prop-route="crm.tab.module.entity.edit" lt-prop-id="gsearchEdit_{{SEID}}" lt-prop-dp='["Leads","{{SEID}}"]' lt-prop-class="link neweditIcon dIB"  data-zcqa="gSearchEditIcon" lt-prop-td='{"recordNum":"{{recordNum}}" }'></link-to>
<a class="mL5 link deleteIcon  dIB"  data-params='{"module":"Leads"}' data-zcqa="gSearchDeleteIcon" href='javascript:;' onclick="showDeletePopup('gsearch_{{SEID}}', 'crm.button.move.to.trash', '', '', this, true);" data-onclick='javascript:searchDelAction("/crm/org673229384/MassDelete.do?module=Leads&fromIndex=1&toIndex=10&id={{SEID}}&type=gsearch&sword=User Name\x2BHorton&searchCategory=Leads&userOpt=null&isajax=true", "Leads")'></a>
</div>{{/ifCondLogic}}
{{else}}
<td nowrap class="tableData bb" style="vertical-align:middle"> <div align="center" id="icon_{{SEID}}" style="visibility:hidden;"></div>{{#ifEquals ISAPPROVED 9}}
<span class="iconlock_ap fR" title='Merging of duplicates is in progress.' alt='Merging of duplicates is in progress.'></span> {{else}}
<span class="iconlock_ap fR" title='Waiting for Approval' alt='Waiting for Approval'></span> {{/ifEquals}}
{{/ifCondLogic}}
{{else}}
<td nowrap class="pR pL0 pR0"> <div id="icon_{{SEID}}" class="alignright pA w40 mainActionIcon" onclick="sE(event)"><a class="link neweditIcon dIB" href="/crm/org673229384/EditEntity.do?module=Leads&id={{SEID}}" data-zcqa="gSearchEditIcon" id="gsearchEdit_{{SEID}}" data-cid="editbtn" data-params='{"module":"Leads","id":"{{SEID}}"}'></a><a class="mL5 link deleteIcon  dIB"  data-params='{"module":"Leads"}' data-zcqa="gSearchDeleteIcon" href='javascript:;' onclick="showDeletePopup('gsearch_{{SEID}}', 'crm.button.move.to.trash', '', '', this, true);" data-onclick='javascript:searchDelAction("/crm/org673229384/MassDelete.do?module=Leads&fromIndex=1&toIndex=10&id={{SEID}}&type=gsearch&sword=User Name\x2BHorton&searchCategory=Leads&userOpt=null&isajax=true", "Leads")'></a>
</div>{{/if}} </td><td>{{{COMPANY}}}</td> <td>{{{LEADSOURCE}}}</td> <td>{{{PHONE}}}</td> <td>{{{EMAIL}}}</td> <td>{{{FULLNAME}}}</td> <td>{{{SMOWNERID}}}</td> </tr>{{/each}}</script></table></td></tr></tbody></table>
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
AnthonyH
  • 27
  • 6

1 Answers1

0

To click() on the element you can use either of the following Locator Strategies:

  • Using cssSelector:

    driver.findElement(By.cssSelector("table.newtable.topband_bb#gsearchTable tbody#header_Leads tr.topband_dv_row a[id^='gsearchEdit'][href*='Leads']")).click();
    
  • Using xpath:

    driver.findElement(By.xpath("//table[@class='newtable topband_bb' and @id='gsearchTable']//tbody[@id='header_Leads']//tr[@class='topband_dv_row']//a[starts-with(@id, 'gsearchEdit') and contains(@href, 'Leads')]")).click();
    

However, as the element is a dynamic element, so to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • Using cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("table.newtable.topband_bb#gsearchTable tbody#header_Leads tr.topband_dv_row a[id^='gsearchEdit'][href*='Leads']"))).click();
    
  • Using xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//table[@class='newtable topband_bb' and @id='gsearchTable']//tbody[@id='header_Leads']//tr[@class='topband_dv_row']//a[starts-with(@id, 'gsearchEdit') and contains(@href, 'Leads')]"))).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • Thanks for your help. I still get an error: Cannot locate an element using By.xpath: //table[@class='newtable topband_bb' and @id='gsearchTable']//tbody[@id='header_Leads']//tr[@class='topband_dv_row']//a[starts-with(@id, 'gsearchEdit') and contains(@href, 'Leads')] – AnthonyH Dec 08 '20 at 22:01
  • @AnthonyHorner How about the options below with WebDriverWait? – DebanjanB Dec 08 '20 at 22:16
  • Thats the error i received trying to use WebDriverWait. I tried both examples using cssSelector and xpath and still it does not seem to find the element. – AnthonyH Dec 09 '20 at 14:01
  • @AnthonyHorner _does not seem to find the element_ isn't a definite error as such. Moreover you won't get _Cannot locate an element using By.xpath_ with `WebDriverWait` – DebanjanB Dec 09 '20 at 14:05
  • After further research with cssSelector, "Can't select any node with this selector: td or td" -- I believe thats probably the same error with xpath – AnthonyH Dec 09 '20 at 15:12