I am working on a project to fill data in a pre existing web table - excel

I am working on a project where I have to fill data in a pre populated dynamic web table. I am able to find the element with the help of XPath in selenium VBA. I am able to click the element. But Whenever I Try to fill data with sendkey command I get the message "Run time error 0.Element not intractable.
When I try sendKey command with normal id of the element or CSS id then it gets accepted but when I try XPath i get the above message.
bot.FindElementByXPath("//td[contains(text(),'XYZ')]/following-sibling::td[5]").SendKeys "54"
<tr style="background-color:White;height:24px;">
<td class="gridtext" align="center">
<span class="checkboxclass"><input id="ctl00_ContentPlaceHolder1_grdUsers_ctl02_chkSelect" type="checkbox" name="ctl00$ContentPlaceHolder1$grdUsers$ctl02$chkSelect" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$grdUsers$ctl02$chkSelect\',\'\')', 0)"></span>
<input type="hidden" name="ctl00$ContentPlaceHolder1$grdUsers$ctl02$hdnUserId" id="ctl00_ContentPlaceHolder1_grdUsers_ctl02_hdnUserId" value="206451744">
</td><td align="center" style="width:2%;">
1
</td><td class="gridtext" align="center">
<span id="ctl00_ContentPlaceHolder1_grdUsers_ctl02_lblStudentId" style="display:inline-block;color:#000000;font-family:Calibri;font-size:12px;font-weight:normal;font-style:normal;width:120px;">091001118051500183</span>
</td><td class="gridtext" align="center">
</td><td class="gridtext" align="left" style="background-color:#FDE9D9;">SHIVAKSHI</td><td class="gridtext" align="left" style="background-color:#FDE9D9;">SANJAI KUMAR</td><td class="gridtext" align="left" style="background-color:#FDE9D9;">SANGEETA</td><td class="gridtext" align="left" style="background-color:#FDE9D9;">19/02/2010</td><td class="gridtext" align="center" style="background-color:#FDE9D9;">
</td><td class="gridtext" align="center">
<input name="ctl00$ContentPlaceHolder1$grdUsers$ctl02$txtNoOfDays" type="text" maxlength="3" id="ctl00_ContentPlaceHolder1_grdUsers_ctl02_txtNoOfDays" class="TextBox" onkeypress="return AllowNumeric_Browser(event, false);" onpaste="return false;" style="width:50px;">
</td><td class="gridtext" align="center">

You need to target the child input tag of the td as the td itself is not interactable. So, you need to add /input to your current path
bot.FindElementByXPath("//td[contains(text(),'XYZ')]/following-sibling::td[5]/input").SendKeys "54"
Here is a similar example where you select the child input of a td based on the parent tr having a td with specific text
bot.Get 'https://datatables.net/examples/api/form.html'
bot.FindElementByXPath("//tr[contains(td/text(), 'Angelica Ramos')]/td[2]/input").SendKeys "test"
Or
//td[contains(text(),'Angelica Ramos')]/following-sibling::td[1]/input

Related

VBA Excel Dynamic HTML code - scraping selenium

I'm trying to automate the filling of an online form, but the input fields seem to be generated at each update having a different ID which doesn't allow the filling as the IDs are always changing.
Is there any solution? suggestions?
Code1 - In this case I can through the name="taxNumber"
<input id="vfenif-1373-inputEl" type="text" size="1" name="taxNumber" class="x-form-field x-form-required-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" autocomplete="off" aria-invalid="false" data-errorqtip="" style="width: 100%;">
Private gc As New Selenium.ChromeDriver
...
gc.FindElementByName("taxNumber").SendKeys ("123456789")
...
Code2 In this case it works once but if you refresh the ID it changes and then it doesn't work
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1047 x-grid-cell-last x-unselectable " id="ext-gen1581"><div unselectable="on" class="x-grid-cell-inner " style="text-align:left;">Submeter Pedido</div></td>
...after refresh
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1047 x-grid-cell-last x-unselectable " id="ext-gen1580"><div unselectable="on" class="x-grid-cell-inner " style="text-align:left;">Submeter Pedido</div></td>
See if this xpath works assuming there is one td with class name "unselectable"
gc.FindElementByXPath("//td[contains(#class,'x-unselectable') and contains(#id,'ext-gen')]")

xpath: How do I extract text within the "strong" tag?

I'm using scrapy and need to extract "Gray / Gray" using xpath selectors.
Here's the html snippet:
<div class="Vehicle-Overview">
<div class="Txt-YMM">
2006 GMC Sierra 1500
</div>
<div class="Txt-Price">
Price : $8,499
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
class="Table-Specs">
<tr>
<td>
<strong>2006 GMC Sierra 1500 Crew Cab 143.5 WB 4WD
SLE</strong>
<strong class="text-right t-none"></strong>
</td>
</tr>
<tr>
<td>
<strong>Gray / Gray</strong><br />
<strong>209,123
Miles
/ VIN: XXXXXXXXXX
</td>
</tr>
</table>
I'm stuck trying to extract "Gray / Gray" within the "strong" tag. Any help is appreciated.
This XPath will work in Scrapy and also in Google/Firefox Developer's Console:
//div[#class='Vehicle-Overview']/table[#class='Table-Specs']//tr[2]/td[1]/strong[1]/text()
You can use this code in your spider:
color = response.xpath("//div[#class='Vehicle-Overview']/table[#class='Table-Specs']//tr[2]/td[1]/strong[1]/text()").extract_first()
You can use this XPath expression with your sample XML/HTML:
//div[#class='Vehicle-Overview']/table[#class='Table-Specs']/tr[2]/td[1]/strong[1]
A full XPath given the full file mentioned below with respect to a namespace "http://www.w3.org/1999/xhtml" can be
/html/body/div/div/div[#class='content-bg']/div/div/div[#class='Vehicle-Overview']/table[#class='Table-Specs']/tr[2]/td[1]/strong[1]

New table row in primefaces repeat

I have a list that I want to display in table along with radio buttons. UI Requirement is that there are grouped in table, 3 in a row. My idea was to use <p:repeat> and <p:fragment> on every third index to close last <tr> and open a new one.
Code is/was:
<table>
<tr>
<p:repeat
value="#{bean.arrayInBean}"
var="value" varStatus="status">
<td>
<span title="#{value.description}">
<input type="radio" value="#{value.code}"
name="valueName" /> #{value.code}
</span>
</td>
<p:fragment rendered="#{(status.index + 1) % 3 eq 0}">
</tr>
<tr>
</p:fragment>
</p:repeat>
</tr>
</table>
Unfortunately i get Error Parsing...The element type "p:fragment" must be terminated by the matching end-tag "</p:fragment>"

I'm trying to select and item from a dropdown kendolistbox in IE with Excel Vba

I found a solution to choosing a fixed selection from a dropdown list. Now all I have to do is figure out how to choose an item based on the choices.
The following chooses the first item in the dropdown, however, I found out that making the dropdown "open" is not necessary.
Changing the select parameter to 2 chooses the second item in the list etc.
I suppose trying to use getElementById and cycling through the innerText may be the way to go, since I don't know any other way.
ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"
Here a section of the web page code.
<input name="Tank.ID" id="Tank_ID" style="width: 200px; display: none;" type="text" data-role="dropdownlist"></span>
'Lots of other stuff in here for formatting
<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.7px; display: block; position: absolute;" data-role="grid">
<table class="k-selectable" role="grid" style="-ms-touch-action: double-tap-zoom pinch-zoom;" data-role="selectable">
<colgroup><col><col></colgroup>
<thead class="k-grid-header" role="rowgroup">
<tr role="row">
<th class="k-header" scope="col" data-title="Tank" data-index="0" data-field="ID"><span class="k-link">Tank</span></th>
<th class="k-header" scope="col" data-title="Capacity" data-index="1" data-field="Capacity"><span class="k-link">Capacity</span></th>
</tr>
</thead>
<tbody role="rowgroup">
<tr class="k-state-selected" aria-selected="true">
<td>179800</td>
<td>202.06</td></tr>
<tr class="k-alt" aria-selected="false">
<td>179801</td>
<td>202.82</td>
</tr>
</tbody>
</table>
</div>
'Code before dropdown
<tbody role="rowgroup">
<tr>
<td>179800</td>
<td>202.06</td></tr>
<tr class="k-alt">
<td>179801</td>
<td>202.82</td>
</tr>
</tbody>
'Code before dropdown opens
<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: none; position: absolute;" data-role="grid">
'Code change after dropdown opens
<div class="k-widget k-grid **k-custom-visible**" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: block; position: absolute;" data-role="grid">
'Code change after making a selection
<tbody role="rowgroup">
<tr class="k-state-selected" aria-selected="true">
<td>179800</td> '<<-----This item selected
<td>202.06</td></tr>
<tr class="k-alt" aria-selected="false"> '<<--If selected then unselected
<td>179801</td> 'otherwise ends at k-alt">
<td>202.82</td>
</tr>
</tbody>
The answer to selecting the first item in a kendoDropDownList ..
ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"

expression engine search result related

I want to display up to 200 words of the related results just in the next line to title
But i am not getting the text that {excerpt} should Display
My code is written below
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
<table border="0" cellpadding="6" cellspacing="1" width="100%">
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
<tr class="{switch}">
{if page_meta_title != ""} <td width="30%" valign="top"><b>{title}</b></td>{/if}
</tr>
<tr><td style="color:red!important">{excerpt}</td></tr>
{if count == total_results}
</table>
{/if}
{paginate}
<p>Page {current_page} of {total_pages} pages {pagination_links}</p>
{/paginate}
{/exp:search:search_results}
</table>
Maybe this was just a typo in your question, but it looks like you have the opening search tag listed twice.
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
<table border="0" cellpadding="6" cellspacing="1" width="100%">
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
Also, the excerpt tag by default allows 50 characters. You can also consider the character limiter plugin (http://devot-ee.com/add-ons/character-limiter) which is a free plugin from Ellis Lab. Once you have that setup, you would use it like so....
{exp:char_limit total="200" exact="no"}{your_text_field}{/exp:char_limit}

Resources