How to click on the element with text as SRP Banner as per the html through Selenium and VBA? - vba

I am trying to click on href using selenium vba in webpage but i am getting below error message.
below is the code which i have tried.
Sub test()
Dim Driver As New Selenium.FirefoxDriver
Driver.Get "http://sums.99acres.com/sums/?profilename=sums"
Driver.FindElementByName("userlogin") _
.SendKeys("xyz") _
.Submit
Driver.FindElementByName("password") _
.SendKeys("12345") _
.Submit
Driver.Get "http://sums.99acres.com/sums/getmyproducts.php?trans_id=1819-T0639786"
Driver.Wait 5000
Driver.FindElementByXPath("//a[contains(#class,'navlink')][contains(text(),'SRP Banner')]").Click
End Sub
I have also tried
Driver.FindElementByLinkText("SRP Banner").Click
Below is the error message i have received
Below is the screen shot where i want to click
Below is the html code.
<frame src="http://sums.99acres.com/sums/products_offered.php?cid=547e14073e8fca793e4629a2acca12c5Si13489029+1534998765+1534998792&trans_id=1819-T0639786" name="left" frameborder="1">
<html><head><script type="text/javascript" src="https://bam.nr-data.net/1/1621b6db8b?a=103016861&v=1071.385e752&to=NV1TZkBVXBdVWk1RVgwXZEBbG0ERWUoWSEsNXERRRkdtC1JfXEpcBhZBWkI%3D&rst=847&ref=http://sums.99acres.com/sums/products_offered.php&ap=736&be=817&fe=840&dc=839&perf=%7B%22timing%22:%7B%22of%22:1534998816389,%22n%22:0,%22f%22:0,%22dn%22:0,%22dne%22:0,%22c%22:0,%22ce%22:0,%22rq%22:13,%22rp%22:798,%22rpe%22:801,%22dl%22:803,%22di%22:838,%22ds%22:838,%22de%22:839,%22dc%22:839,%22l%22:839,%22le%22:840%7D,%22navigation%22:%7B%7D%7D&at=GRpQEAhPTxk%3D&jsonp=NREUM.setToken"></script><script src="https://js-agent.newrelic.com/nr-1071.min.js"></script><script type="text/javascript">window.NREUM||(NREUM={}),__nr_require=function(e,t,n){function r(n){if(!t[n]){var o=t[n]={exports:{}};e[n][0].call(o.exports,function(t){var o=e[n][1][t];return r(o||t)},o,o.exports)}return t[n].exports}if("function"==typeof __nr_require)return __nr_require;for(var o=0;o<n.length;o++)r(n[o]);return r}({1:[function(e,t,n){function r(){}function o(e,t,n){return function(){return i(e,[f.now()].concat(u(arguments)),t?null:this,n),t?void 0:this}}var i=e("handle"),a=e(2),u=e(3),c=e("ee").get("tracer"),f=e("loader"),s=NREUM;"undefined"==typeof window.newrelic&&(newrelic=s);var p=["setPageViewName","setCustomAttribute","setErrorHandler","finished","addToTrace","inlineHit","addRelease"],d="api-",l=d+"ixn-";a(p,function(e,t){s[t]=o(d+t,!0,"api")}),s.addPageAction=o(d+"addPageAction",!0),s.setCurrentRouteName=o(d+"routeName",!0),t.exports=newrelic,s.interaction=function(){return(new r).get()};var m=r.prototype={createTracer:function(e,t){var n={},r=this,o="function"==typeof t;return i(l+"tracer",[f.now(),e,n],r),function(){if(c.emit((o?"":"no-")+"fn-start",[f.now(),r,o],n),o)try{return t.apply(this,arguments)}catch(e){throw c.emit("fn-err",[arguments,this,e],n),e}finally{c.emit("fn-end",[f.now()],n)}}}};a("setName,setAttribute,save,ignore,onEnd,getContext,end,get".split(","),function(e,t){m[t]=o(l+t)}),newrelic.noticeError=function(e){"string"==typeof e&&(e=new Error(e)),i("err",[e,f.now()])}},{}],2:[function(e,t,n){function r(e,t){var n=[],r="",i=0;for(r in e)o.call(e,r)&&(n[i]=t(r,e[r]),i+=1);return n}var o=Object.prototype.hasOwnProperty;t.exports=r},{}],3:[function(e,t,n){function r(e,t,n){t||(t=0),"undefined"==typeof n&&(n=e?e.length:0);for(var r=-1,o=n-t||0,i=Array(o<0?0:o);++r<o;)i[r]=e[t+r];return i}t.exports=r},{}],4:[function(e,t,n){t.exports={exists:"undefined"!=typeof window.performance&&window.performance.timing&&"undefined"!=typeof window.performance.timing.navigationStart}},{}],ee:[function(e,t,n){function r(){}function o(e){function t(e){return e&&e instanceof r?e:e?c(e,u,i):i()}function n(n,r,o,i){if(!d.aborted||i){e&&e(n,r,o);for(var a=t(o),u=m(n),c=u.length,f=0;f<c;f++)u[f].apply(a,r);var p=s[y[n]];return p&&p.push([b,n,r,a]),a}}function l(e,t){v[e]=m(e).concat(t)}function m(e){return v[e]||[]}function w(e){return p[e]=p[e]||o(n)}function g(e,t){f(e,function(e,n){t=t||"feature",y[n]=t,t in s||(s[t]=[])})}var v={},y={},b={on:l,emit:n,get:w,listeners:m,context:t,buffer:g,abort:a,aborted:!1};return b}function i(){return new r}function a(){(s.api||s.feature)&&(d.aborted=!0,s=d.backlog={})}var u="nr#context",c=e("gos"),f=e(2),s={},p={},d=t.exports=o();d.backlog=s},{}],gos:[function(e,t,n){function r(e,t,n){if(o.call(e,t))return e[t];var r=n();if(Object.defineProperty&&Object.keys)try{return Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!1}),r}catch(i){}return e[t]=r,r}var o=Object.prototype.hasOwnProperty;t.exports=r},{}],handle:[function(e,t,n){function r(e,t,n,r){o.buffer([e],r),o.emit(e,t,n)}var o=e("ee").get("handle");t.exports=r,r.ee=o},{}],id:[function(e,t,n){function r(e){var t=typeof e;return!e||"object"!==t&&"function"!==t?-1:e===window?0:a(e,i,function(){return o++})}var o=1,i="nr#id",a=e("gos");t.exports=r},{}],loader:[function(e,t,n){function r(){if(!x++){var e=h.info=NREUM.info,t=d.getElementsByTagName("script")[0];if(setTimeout(s.abort,3e4),!(e&&e.licenseKey&&e.applicationID&&t))return s.abort();f(y,function(t,n){e[t]||(e[t]=n)}),c("mark",["onload",a()+h.offset],null,"api");var n=d.createElement("script");n.src="https://"+e.agent,t.parentNode.insertBefore(n,t)}}function o(){"complete"===d.readyState&&i()}function i(){c("mark",["domContent",a()+h.offset],null,"api")}function a(){return E.exists&&performance.now?Math.round(performance.now()):(u=Math.max((new Date).getTime(),u))-h.offset}var u=(new Date).getTime(),c=e("handle"),f=e(2),s=e("ee"),p=window,d=p.document,l="addEventListener",m="attachEvent",w=p.XMLHttpRequest,g=w&&w.prototype;NREUM.o={ST:setTimeout,SI:p.setImmediate,CT:clearTimeout,XHR:w,REQ:p.Request,EV:p.Event,PR:p.Promise,MO:p.MutationObserver};var v=""+location,y={beacon:"bam.nr-data.net",errorBeacon:"bam.nr-data.net",agent:"js-agent.newrelic.com/nr-1071.min.js"},b=w&&g&&g[l]&&!/CriOS/.test(navigator.userAgent),h=t.exports={offset:u,now:a,origin:v,features:{},xhrWrappable:b};e(1),d[l]?(d[l]("DOMContentLoaded",i,!1),p[l]("load",r,!1)):(d[m]("onreadystatechange",o),p[m]("onload",r)),c("mark",["firstbyte",u],null,"api");var x=0,E=e(4)},{}]},{},["loader"]);</script>
<title>SUMS : MAINPAGE</title>
<style>
a:link, a:visited, a:active{color:#0000ff;}
</style>
</head>
<body style="font-family:verdana, Helvetica, sans-serif;color:#000;font-size:11px;">
<br><br><br>
<table width="80%" align="center" style="font-family:verdana, Helvetica, sans-serif;color:#000;font-size:11px;">
<tbody><tr><td>
<table width="100%" aligh="center"><tbody><tr align="center">
<td width="25%" style="color:#9400D3;font-size:14px;text-decoration:underline;">SUMS</td>
<td width="25%" style="color:#9400D3;font-size:14px;text-decoration:underline;">CRM</td>
<td width="25%" style="color:#9400D3;font-size:14px;text-decoration:underline;">Mis</td>
<td width="25%" style="color:#9400D3;font-size:14px;text-decoration:underline;"><!--a href="../sums/logout.php?name=vishal&cid=547e14073e8fca793e4629a2acca12c5Si13489029+1534998765+1534998807" -->Logout</td>
</tr></tbody></table><br>
</td></tr></tbody></table>
<br><br><table width="300" border="0" cellspacing="2" cellpadding="2" style="font-family:verdana, Helvetica, sans-serif;color:#000;font-size:11px;">
<tbody><tr> <td colspan="2" style="color:#ff6600;font-weight:bold;font-size:18px;">PRODUCTS OFFERED</td></tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="19">1.</td>
<td width="374"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'"><b><a target="right" href="http://sums.99acres.com/sums/zedo_srp_products.php?module=SUMS&trans_id=1819-T0639786&productType=SRPB&prod=SRPB" class="navlink">SRP Banner </a></b> <span style="COLOR: gray"> (Pending: 1 of 1)</span></span></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</tbody></table>
<br><br>
<script type="text/javascript">window.NREUM||(NREUM={});NREUM.info={"beacon":"bam.nr-data.net","licenseKey":"1621b6db8b","applicationID":"103016861","transactionName":"NV1TZkBVXBdVWk1RVgwXZEBbG0ERWUoWSEsNXERRRkdtC1JfXEpcBhZBWkI=","queueTime":0,"applicationTime":736,"atts":"GRpQEAhPTxk=","errorBeacon":"bam.nr-data.net","agent":""}</script>
</body></html>

As per the HTML you have shared to click on the desired element first you need to Switch To the Frame then lookout for the element and you can use the following solution:
Driver.Get "http://sums.99acres.com/sums/getmyproducts.php?trans_id=1819-T0639786"
Driver.Wait 5000
Driver.SwitchToFrame.FindElementByXPath("//frame[#name='left' and contains(#src,'http://sums.99acres.com/sums/products_offered.php')]", timeout:=10000)
Driver.Wait 3000
Driver.FindElementByXPath("//a[#class='navlink' and contains(#href,'http://sums.99acres.com/sums/zedo_srp_products.php?module')][contains(.,'SRP Banner')]").Click

This is too long to fit as a comment legibly. Can you try chucking the pageSource HTML into an HTMLDocument and clicking from there? Following code lines go in continuing from the Wait line you already have, reproduced below:
Driver.Wait 5000
Dim html As New HTMLDocument, ele As Object
html.body.innerHTML = Driver.PageSource
Set ele = html.getElementsByTagName("form")(0)
ele.querySelector("a[href*='trans_id=1819']").Click
I have left it in several stages so you can debug whether the ele is even set before attempting a click.

Related

Excel VBA to change dropdown menu within a form

I tried some alternatives, but with no success, to change the combobox you can find the website code below (It looks that the problem is that the combobox is inside a form - I can't change an input box as well):
<form action="procRelLmPorData.asp" method="post" target="ifrmGerar" id="frmGerar" name="frmGerar">
<input type="hidden" name="ordem" id="ordem" value="" />
<table style="width:100%;" cellpadding="0" cellspacing="0">
<tr>
<th class="header">Licenças Médicas por Data</th>
</tr>
</table>
<table style="border-bottom:#048282 thin solid;width:100%;">
<tr>
<td style="width:20%;vertical-align:top;">
<table>
<tr>
<td>Regional: </td>
<td>
<select style="width:200px" name="regional" id="regional" onchange="comboFilial(this.value);comboSetor('');">
<option value="">Selecione</option>
<option value='67'>RJ</option>
</select>
I've tried the codes below to solve it:
Assuming that objie = InternetExplorer.Application
1st -
objie.Document.forms("frmGerar").getElementsByTagName("select")("regional").Value = 67
2nd - objie.Document.forms("frmGerar").Item("regional").Value = 67
3rd - objie.Document.getElementById("regional").selectedindex= 2
Can you figure what's the problem?
EDIT
I've found that the form is inside an IFrame, you can find the code below:
<iframe name="ifrmCentro" id="ifrmCentro" src="mapPath.asp?codMenu=404" frameborder="0" style="border: 0px currentColor; border-image: none; width: 100%; height: 177px; display: block;"></iframe>
I made it.
The problem was the iFrame, which I had to navigate through.
.Navigate Website & "mapPath.asp?codMenu=404"
Do While .Busy Or .ReadyState <> 4
DoEvents
Loop
After that I could fill the boxes and select combobox:
.Document.all("datInicial").Value = Range("A6").Text
.Document.all("datFinal").Value = Range("A7").Text
.Document.all("regional").Value = 67
Thanks!

How to click a link by text in Selenium web driver java

I have many links in my page.One with text "Add policyhoder" ,one with text " Add" only and another "Add PP". I need to click link by text .I am using below code to click link having text as "Add" only but it is clicking very first link having "Add" in its text i.e. ""Add PP" available on screen.Please can u help
Driver.findElement(By.linkText("Add"));
My requirement is to click a link with exact text match . for example "Add" here
<td width="100%" colspan="7">
<table width="100%" cellspacing="0" cellpadding="1" valign="bottom">
<input id="hidPoClaim" type="hidden" onblur="ResetScript(this);" onfocus="HighlightScript(this);" value=" PolicySummary " callfunction="" size="" name="/Root/ACORD/InsuranceSvcRs/com.c_HomePolicyInquiryRs/co.cc_AvailableFunctions[com._FunctionName='PoSummary' and com.csc_FunctionName[#Action='ShowPolicyClaims']]">
<tbody>
<tr>
<td width="25%" valign="bottom" colspan="1">
<strong>
<font class="flabel">Policy Claims History:</font>
</strong>
</td>
<td width="20%" valign="bottom" colspan="1">
<font class="flabel"> </font>
<a class="fLabel" onclick="INFCaptureControlID(this); DoLink('POLICYLOSS','','ADD' );return false; " onblur="ResetScript(this);return true;" onfocus="HighlightScript(this);" delimiter="|" screenaction="ADD" href="" screen="Y" objecttype="POLICYLOSS" type="Link" context="Screen">**Add**</a>
</td>
<td width="20%" valign="bottom" colspan="1">
<td align="Center" width="15%" valign="bottom" colspan="1">
<td width="20%" colspan="1">
</tr>
</tbody>
</table
Thanks
Dev
If it the there are 2 elements with the word "Add", Then try something like this:
List<WebElement> list = driver.findElements(By.linkText("Add"));
list.get(1).click();
To find the element by searching for the exact text, then using xpath will be more helpful.
// For "Add" link, according to the HTML you've added to the question
driver.findElement(By.xpath("//a[text()='**Add**']")).click();
I assume because when you click on first link it opens that link page in same tab and can not find second link element as page changed , so you have to open that link page in new tab in.
I think your code would be :
String Newtab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver.findElement(By.linkText("Add policyhoder")).sendKeys(Newtab);
driver.findElement(By.linkText("Add")).click();
Now above code will work for you.
you can try using
driver.findElement(By.xpath("//a[text()='Add']"));
This would match exact text for you

How can I reach the link inside TR using XPATH

This HTML code has menu of targets and you need to select one target. One of these targets is ANY TARGET to continue process.
<tr id="mainForm:nav-panel-tab-set:0:trigger-selectTable:0" class=" iceRowSelMouseOver" tabindex="0" onmouseover="this.className=' iceRowSelMouseOver';" onmouseout="Ice.enableTxtSelection(document.body); this.className='iceDatTblRow1 selectable-rowRow1 iceRowSel'" onmousedown="return Ice.preventTextSelection(event);" ondblclick="Ice.registerDblClick(this);" onclick="Ice.registerClick(this,'mainForm:nav-panel-tab-set:0:trigger-selectTableclick_row','mainForm:nav-panel-tab-set:0:trigger-selectTableclick_count','0','mainForm',200,true,event,false,'mainForm:nav-panel-tab-set:0:trigger-selectTablesel_rows','');">
<td class="iceDatTblCol1 selectable-rowCol1" scope="row">
<a id="mainForm:nav-panel-tab-set:0:trigger-selectTable_idx_0" class="iceHdnLnk" onfocus="return Ice.tblRowFocus(this, false);" onblur="return Ice.tblRowBlur(this);" href="#">
<img alt="" src="/ice/xmlhttp/css/xp/css-images/spacer.gif"/>
</a>
<span id="mainForm:nav-panel-tab-set:0:trigger-selectTable:0:j_idt1417" class="iceOutTxt">ANY TARGET</span>
</td>
<td class="iceDatTblCol2 selectable-rowCol2">
<span id="mainForm:nav-panel-tab-set:0:trigger-selectTable:0:j_idt1419" class="iceOutTxt select-icon">»</span>
</td>
</tr>
How can I reach the ANY TARGET to click on >> to add using XPATH?
Extra Information:
The previous code is for sub window to add target. the main window code is:
<tr class="icePnlGrdRow1 settings-tableRow1">
<td id="mainForm:nav-panel-tab-set:0:j_idt1305-2-0" class="icePnlGrdCol1 settings-tableCol1">
<table id="mainForm:nav-panel-tab-set:0:j_idt1326" class="icePnlGrd settingsLabel">
<tbody>
<tr class="icePnlGrdRow1 settingsLabelRow1">
<td id="mainForm:nav-panel-tab-set:0:j_idt1326-0-0" class="icePnlGrdCol1 settingsLabelCol1">
<span id="mainForm:nav-panel-tab-set:0:j_idt1327" class="iceOutTxt label">Target</span>
</td>
</tr>
<tr class="icePnlGrdRow2 settingsLabelRow2">
<td id="mainForm:nav-panel-tab-set:0:j_idt1326-1-0" class="icePnlGrdCol1 settingsLabelCol1">
<span id="mainForm:nav-panel-tab-set:0:j_idt1328" class="iceOutTxt sidenote">Target or group</span>
</td>
</tr>
</tbody>
</table>
</td>
<td id="mainForm:nav-panel-tab-set:0:j_idt1305-2-1" class="icePnlGrdCol2 settings-tableCol2">
<table id="mainForm:nav-panel-tab-set:0:j_idt1329" class="icePnlGrd search">
<tbody>
<tr class="icePnlGrdRow1 searchRow1">
<td id="mainForm:nav-panel-tab-set:0:j_idt1329-0-0" class="icePnlGrdCol1 searchCol1">
<span id="mainForm:nav-panel-tab-set:0:j_idt1330" class="iceOutTxt"/>
</td>
<td id="mainForm:nav-panel-tab-set:0:j_idt1329-0-1" class="icePnlGrdCol2 searchCol2">
<input id="mainForm:nav-panel-tab-set:0:j_idt1331" class="iceCmdBtn" type="image" src="/ice/img/search-icon.png" onfocus="setFocus(this.id);" onclick="iceSubmitPartial(form, this, event);return false;" onblur="setFocus('');" name="mainForm:nav-panel-tab-set:0:j_idt1331"/>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
I used ID to click on the targets to open the sub window
//*[#id='mainForm:nav-panel-tab-set:0:j_idt1331']
However, I did not get any response to add any target to my main window either I used the solutions you mentioned.
You can reach the span containing "ANY TARGET":
//span[text() = "ANY TARGET"]
You can extend this to reach the span containing ">>" in the td immediately following the td that contains "ANY TARGET":
//td[span[text() = "ANY TARGET"]]/following-sibling::td[1]/span[text() = ">>"]
Try to focus on the first TD and then click on the Span element.
IWebElement td = browser_drive.FindElement(By.Id("mainForm:nav-panel-tab-set:0:trigger-selectTable:0")).FindElements(By.TagName("td"))[0];
IWebElement anytext = td.FindElement(By.Id("mainForm:nav-panel-tab-set:0:trigger-selectTable:0:j_idt1417"));
OpenQA.Selenium.Interactions.Actions act = new OpenQA.Selenium.Interactions.Actions(browser_drive);
act.MoveToElement(td).Click(anytext);
(Coded using C#, there must be an alternative. Pseudo code, not complied)

Getting Error while identifying an element in Selenium WebDriver

I have to select the above highlighted link New V1 Project but I am not able to identify the element.
I've tried using linktext function but it is giving error... can anybody help?
Hierachy is something like:-
<tbody>
<tr>
<td width="40" align="center">
<td width="5">
<td align="center" noWrap="" style="border-bottom-color: black; border-bottom-width: 1px; border-bottom-style: solid;" bgColor="#cccccc">
<a class="navSelected" onmouseover="window.status=''; return true" onmouseout="window.status=''; return true" href="index.cfm?fuseaction=project.view&version=1">
<td width="5">
<td width="5">
<td align="center" noWrap="" style="border-bottom-color: black; border-bottom-width: 1px; border-bottom-style: solid;" bgColor="#cccccc">
<a class="nav" onmouseover="window.status=''; return true" onmouseout="window.status=''; return true" href="index.cfm?fuseaction=project.create_form&version=1">
<td width="5">
<td width="5">
<td align="center" noWrap="" style="border-bottom-color: black; border-bottom-width: 1px; border-bottom-style: solid;" bgColor="#cccccc">
<a class="nav" onmouseover="window.status=''; return true" onmouseout="window.status=''; return true" href="index.cfm?fuseaction=project.create_form&version=2">
</tr>
</tbody>
please see the highlighted HTML code in image... I am not sure how this Text element is linked with a tag
My Code that I've used to identify element is:
WebElement v1Link = driver.findElement(By.linktext("New V1 Project"));
WebElement v1Link = driver.findElement(By.xpath("//tr/td[3]/a[#text()= 'New v1 Project']"));
but none of the above 2 methods are working... please somebody help.
You can find the link by the following xpath:
//td/a[normalize-space(text()) = 'New V1 Project']
FYI, your version of xpath was almost correct:
no need to put # before the text()
the text is New V1 Project, not New v1 Project
you need to use normalize-space()
Hope that helps.
Try using cssselector-
WebElement v1Link = driver.findElement(By.cssSelector("a.nav[href='index.cfm?fuseaction=project.create_form&version=2']"));

Difficulty Finding Table CheckBoxes

I'm trying to use Excel VBA to perform a very manual process in IE. I've worked with VBA and IE enough to do easy tasks like enter text into fields or interact with buttons, but I'm having a difficult time wrapping my head around this.
I have a list of fields in Excel: First Name, Last Name, Email Address. There are over two thousand rows of information in the spreadsheet. The website I'm working with has a list of over three thousand rows of information (same information with the addition of a checkbox), except it only loads a maximum of 100 rows at a time. Every row of data in Excel exists in the web tool.
I'd like to have my procedure iterate over the names and check the corresponding row on the webpage. The problem is figuring out how to identify the input id for the corresponding checkbox. I'm not very familiar with HTML so my code is very rudimentary... I've spent much of the day writing this:
Sub Test()
Dim str As String
Dim ie As SHDocVw.InternetExplorer
Dim doc As HTMLDocument
Dim tbls As Object
Dim tbl As Object
Dim trow As Object
Dim trs As Object
Dim Cell As Range
Set ie = New SHDocVw.InternetExplorer
ie.navigate "https://test.com"
ie.Visible = True
Set doc = ie.Document
Set tbls = doc.getElementsByTagName("TABLE")
For Each Cell In Range("A2:A2200")
For Each tbl In tbls
For Each trow In tbl.Rows
If InStr(1, trow.Cells(i).innerText, Cell.Offset(0, 1) & ", " & Cell) > 0 Then
Debug.Print trow.Cells(0).innerText
Stop
End If
Next trow
Next tbl
Next Cell
End Sub
The above code is able to identify the cell on the page that matches the cell in the workbook, but I can't figure out how to find the id to the associated checkbox. The site is private, so I can't provide a link. See below for what appears to be the relevant piece of source code for the site:
<div>
<table cellspacing="0" border="0" id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults" style="border-color:Black;border-width:1px;border-style:Solid;width:100%;border-collapse:collapse;">
<tr>
<td colspan="6">
<table id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_tabPager" border="0" cellpadding="5" width="100%">
<tr>
<td style="border-style:none;">
<a id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_lbPrev" disabled="disabled">Previous</a>
<a id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_lbNext" disabled="disabled">Next</a>
</td>
<td style="border-style:none;" align="right">
<b>Showing:</b>
<span id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow"><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_0" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="10" checked="checked" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_0">10 People</label><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_1" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="25" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow$1\',\'\')', 0)" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_1">25 People</label><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_2" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="50" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow$2\',\'\')', 0)" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_2">50 People</label><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_3" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="100" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow$3\',\'\')', 0)" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_3">100 People</label></span>
</td>
</tr>
<tr id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_trSelectOptions">
<td colspan="2" style="border-style: none;" align="left">
Select All on Page
Clear All on Page
<a class="link_w_img" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$ctl09", "", true, "", "", false, true))">
<img src="/images/all.gif" />
<span>Select Entire List</span></a>
<a class="link_w_img" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$ctl11", "", true, "", "", false, true))">
<img src="/images/none.gif" />
<span>Clear Entire List</span></a>
</td>
</tr>
</table>
</td>
</tr>
<tr class="gridheader" align="left">
<th scope="col">Select</th>
<th scope="col">Last Name</th>
<th scope="col">First Name</th>
<th scope="col">Middle Name</th>
<th scope="col">E-mail Address</th>
<th scope="col" style="width:0px;"> </th>
</tr>
<tr class="griditem" align="center">
<td>
<input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_SelectCheckBox" type="checkbox" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl03$SelectCheckBox" />
</td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();">Demo1</td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();">Test</td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();"> </td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();">Demo1#Test.com</td>
<td style="width:0px;">
<div id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip" class="popup">
<div class="popupbg">
<table>
<tr>
<td style="vertical-align:top;">
<span id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_lblName" style="font-weight:bold;">Demo1, Test </span>
<br />E-mail:<span id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_lblEmail">Demo1#Test.com</span><br />
<table cellspacing="0" border="0" id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_dgDemos" style="border-style:None;border-collapse:collapse;margin-top:-1.25em;">
<tr>
<td>
</td><td>
</td>
</tr><tr>
<td>
Employee ID:
</td><td>
N/A
</td>
</tr><tr>
<td>
Job Title:
</td><td>
N/A
</td>
</tr><tr>
<td>
Location:
</td><td>
N/A
</td>
</tr>
</table>
</td>
<td style="width:50px;vertical-align:top;">
<img src="/images/user_popup.jpg" border="0" width="48" height="48"/>
</td>
</tr>
</table>
</div>
</div>
</td>
In the above example, the Last Name is Demo1, the First Name is Test, and the Email is Demo1#Test.com, and the input id for the checkbox is ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_SelectCheckBox.
My question is, how do I identify the input id after I've identified table row? Or, perhaps that's impossible and I'm going about this the wrong way? Any thoughts will be much appreciated.
Edit
This is what I tried that gives me the Runtime error (Object variable or With block variable not set):
trow.Cells(0).getElementsByTagName("input")(0).Click
I also tried this:
set input = trow.Cells(0).getElementsByTagName("input")(0)
input.Click
And finally, both these produce the same error:
Debug.Print trow.Cells(0).getElementsByTagName("input")(0).innerText
Debug.Print trow.Cells(0).getElementsByTagName("input")(0)
This is the output of the Debug.Print in my original code:
Demo1, Test
E-mail: Demo1#Test.com
Employee ID: N/A
Job Title: N/A
Location: N/A
The only pieces I care about (in the output) are the first two lines, the email and name of the individual.
This test worked for me. Looks like the rows you want all have class="griditem", so you can check all table rows for that class name. When you find a match on that and on your cell values, you should be able to find the checkbox as shown.
Sub Tester()
Dim d As New HTMLDocument, trs, rw
d.body.innerHTML = _
"<section><table><tr class='griditem'><td>" & _
"<input type='checkbox' id='id_1'></td>" & _
"<td>Foo</td></tr><tr class='griditem'><td>" & _
"<input type='checkbox' id='id_2'></td>" & _
"<td>Bar</td></tr></table></section>"
Set trs = d.getElementsByTagName("tr")
For Each rw In trs
If rw.className = "griditem" Then
'check cell values for match....
Debug.Print rw.Cells(0).getElementsByTagName("input")(0).ID
End If
Next rw
End Sub
Give a try to this.
Set ElementCol = ie.Document.getElementsByTagName("input")
For Each btnInput In ElementCol
'your code here
Next btnInput