Selecting Date from the Datepicker. How do I do that using WATIR - watir

I don't know how to select the date from the date picker, For an example, If I want to select 1/5/2022, how would I do that?
here is the pic
Here is the Html
<div style="visibility: visible; overflow: visible; left: 589px; top: 193px; position: absolute;"
class="gwt-PopupPanel">
<div class="popupContent">
<table class="gwt-DatePicker" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="vertical-align: top;" align="left">
<table class="datePickerMonthSelector">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td width="1">
<div tabindex="0" class="datePickerPreviousButton" role="button" aria-pressed="false">
<input type="text" tabindex="-1" aria-hidden="true"
style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;">
<div class="html-face">«</div>
</div>
</td>
<td width="1">
<div tabindex="0" class="datePickerPreviousButton" role="button" aria-pressed="false">
<input type="text" tabindex="-1" aria-hidden="true"
style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;">
<div class="html-face">‹</div>
</div>
</td>
<td class="datePickerMonth" width="100%">Nov 2022</td>
<td width="1">
<div tabindex="0" class="datePickerNextButton datePickerNextButton-up" role="button"
aria-pressed="false"><input type="text" tabindex="-1" aria-hidden="true"
style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;">
<div class="html-face">›</div>
</div>
</td>
<td width="1">
<div tabindex="0" class="datePickerNextButton datePickerNextButton-up" role="button"
aria-pressed="false"><input type="text" tabindex="-1" aria-hidden="true"
style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;">
<div class="html-face">»</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="vertical-align: top;" align="left">
<table class="datePickerDays" cellspacing="0" cellpadding="0" border="0">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td class="datePickerWeekendLabel">S</td>
<td class="datePickerWeekdayLabel">M</td>
<td class="datePickerWeekdayLabel">T</td>
<td class="datePickerWeekdayLabel">W</td>
<td class="datePickerWeekdayLabel">T</td>
<td class="datePickerWeekdayLabel">F</td>
<td class="datePickerWeekendLabel">S</td>
</tr>
<tr>
<td>
<div tabindex="-1" aria-selected="false"
class="datePickerDay datePickerDayIsWeekend datePickerDayIsFiller ">30
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
31
</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">1</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">2</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">3</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">4</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
5
</div>
</td>
</tr>
<tr>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
6
</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">7</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">8</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">9</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">10</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">11</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
12
</div>
</td>
</tr>
<tr>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
13
</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">14</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">15</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">16</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">17</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">18</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
19
</div>
</td>
</tr>
<tr>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
20
</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">21</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">22</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">23</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">24</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">25</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
26
</div>
</td>
</tr>
<tr>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay datePickerDayIsWeekend ">
27
</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">28</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">29</div>
</td>
<td>
<div tabindex="0" aria-selected="false" class="datePickerDay ">30</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
1
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
2
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false"
class="datePickerDay datePickerDayIsWeekend datePickerDayIsFiller ">3
</div>
</td>
</tr>
<tr>
<td>
<div tabindex="-1" aria-selected="false"
class="datePickerDay datePickerDayIsWeekend datePickerDayIsFiller ">4
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
5
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
6
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
7
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
8
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false" class="datePickerDay datePickerDayIsFiller ">
9
</div>
</td>
<td>
<div tabindex="-1" aria-selected="false"
class="datePickerDay datePickerDayIsWeekend datePickerDayIsFiller ">10
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>

The general approach needs to be:
Use the month previous/next buttons to select the month/year
Click the specific day (making sure to ignore the days for the previous/next month)
The code would look like:
# The day you would like to pick
target_date = Time.parse('1/5/2022')
# Pick the month/year (by determining how many months in the past/future you need to go)
current_date = Time.parse(browser.td(class: 'datePickerMonth').text)
months_to_increment = (target_date.year * 12 + target_date.month) - (current_date.year * 12 + current_date.month) # From https://stackoverflow.com/a/9428676/1200545
months_to_increment.abs.times do
if months_to_increment > 0
browser.div(class: 'datePickerNextButton', index: 0).click
else
browser.div(class: 'datePickerPreviousButton', index: 1).click
end
end
# Pick the day (ignoring the datePickerDayIsFiller divs as they are the previous/next month)
browser.div(text: target_date.day.to_s, class: ['datePickerDay', '!datePickerDayIsFiller']).click

Related

How to get only rely content(black color) and not included quote(blue color) content using Selenium and Python

I want to know what to get some content not include quote content.
The following url is the target webpage:
https://forumd.hkgolden.com/view.aspx?type=BW&message=7219211
I must use a full xpath to get their content. I want to get black color content and I don't want to get blue content, but when I use the following code. I got blue and blank content together.
content = driver_blank.find_element_by_xpath('/html/body/form/div[5]/div/div/div[2]/div[1]/div[5]/table[8]/tbody/tr/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/div')
print(content.text)
The following is their html code:
<table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom: 7px;">
<tbody>
<tr>
<td align="left">
<table class="repliers">
<tbody>
<tr hc7uwnfktbez9="" id="XoBTa" userid="461194" username="浅川梨奈">
<td class="repliers_left" style="background-color: #F3F2F1;">
<div>
<a name="275220714"></a>
<a href="javascript: ToggleUserDetail(6, 'XoBTa');" style="font-weight: bold; color: #FF0066;">
浅川梨奈
</a>
<br>
<br>
<div id="ThreadUser6" style="position: relative;">
<a href="/ProfilePage.aspx?userid=461194" style="text-decoration: none;">
<img src="/icons/97.gif" style="border-width: 0px;" alt="Logo">
</a>
<br>
<br>
<img src="/labels/4.gif" style="border-width: 0px;" alt="Member">
</div>
</div>
</td>
<td style="background-color: #F3F2F1; height: 100%; border: solid 1px #111111; vertical-align: top;">
<table class="repliers_right" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="vertical-align: top;">
<div class="ContentGrid">
<blockquote><div style="color: #0000A0;">有冇第隻款<img data-icons=":-[lm" src="/faces/lomore/angry.gif" alt=":-[lm"> <img data-icons=":-(lm" src="/faces/lomore/frown.gif" alt=":-(lm"> 我想要呢兩隻</div></blockquote>
<br>
係囉,反應好既會唔會考慮出其他?
<br>
我都想要其他
<img data-icons="^3^lm" src="/faces/lomore/kiss.gif" alt="^3^lm">
<img data-icons="[bomb]lm" src="/faces/lomore/bomb.gif" alt="[bomb]lm">
<br><br><br>
</div>
</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: top;">
<div id="lineImage6" style="display: block; overflow: hidden;">
</div>
</td>
</tr>
<tr>
<td style="width: 100%; text-align: right;">
<div style="float: right; vertical-align: bottom; margin-top: 5px;">
<div id="lauming6" style="float: left; vertical-align: bottom;"></div>
<a class="btn btn_small btn_bookmark" href="Javascript:bookmarkThis(7219211)" id="laumingHref">留名</a>
<a class="btn btn_small btn_complain" href="contactus.aspx?messageid=7219211&replyid=275220714">投訴文章</a>
<a class="btn btn_small btn_quote" href="Javascript:QuoteReply(7219211,275220714);">快速引用</a>
<a class="btn btn_small btn_quote" href="post.aspx?mt=Y&rid=275220714&id=7219211&page=2">引用原文</a>
<span style="font-size: 12px; color:gray;">
15/4/2020 13:18
</span>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
I hope to use start-to, not, or contains instruction to finish it.
Can anyone help me? Thanks~~~

Beautifulsoup problem of scraping text in array

Data=
<div class="dojoxGridView" id="dojox_grid__View_1" role="presentation" style="width: 1900px; height: 721px; left: 1px; top: 0px;" widgetid="dojox_grid__View_1">
<input class="dojoxGridHiddenFocus" dojoattachpoint="hiddenFocusNode" role="presentation" type="checkbox"/>
<input class="dojoxGridHiddenFocus" role="presentation" type="checkbox"/>
<div class="dojoxGridScrollbox" dojoattachpoint="scrollboxNode" role="presentation" style="height: 721px;">
<div class="dojoxGridContent" dojoattachpoint="contentNode" hidefocus="hidefocus" role="presentation" style="height: 504px; width: 1900px;">
<div role="presentation" style="position: absolute; left: 0px; top: 0px;">
<div aria-selected="false" class="dojoxGridRow" role="row" style="">
<table border="0" cellpadding="0" cellspacing="0" class="dojoxGridRowTable" role="presentation" style="width: 1900px;">
<tbody>
<tr>
<td class="dojoxGridCell" idx="0" role="gridcell" style="display:none;width:100px;" tabindex="-1">
78126
</td>
<td class="dojoxGridCell" idx="1" role="gridcell" style="width:10%;" tabindex="-1">
Approved Plan
</td>
<td class="dojoxGridCell" idx="2" role="gridcell" style="width:10%;" tabindex="-1">
G-10
</td>
<td class="dojoxGridCell" idx="3" role="gridcell" style="width:40%;" tabindex="-1">
ROOF PLAN
</td>
</tr>
</tbody>
</table>
</div>
Input=
source = driver.page_source
soup = BeautifulSoup(source, "lxml")
print(soup. prettify())
for article in soup.find_all('div', class_='dojoxGridContent'):
drawing_no = article.find_all('td', class_='dojoxGridCell', idx='3')
# ->need one more line to extract text
print(""drawing_no")
Output=
<td class="dojoxGridCell" idx="3" role="gridcell" style="width:40%;" tabindex="-1">ROOF PLAN</td> ...
I just want to extract "ROOF PLAN" how should I edit my code?
I tried drawing_no.text and drawing_no.value but it said "no attribute".
Thanks for your help!
try followig code
source="""<div class="dojoxGridView" id="dojox_grid__View_1" role="presentation" style="width: 1900px; height: 721px; left: 1px; top: 0px;" widgetid="dojox_grid__View_1">
<input class="dojoxGridHiddenFocus" dojoattachpoint="hiddenFocusNode" role="presentation" type="checkbox"/>
<input class="dojoxGridHiddenFocus" role="presentation" type="checkbox"/>
<div class="dojoxGridScrollbox" dojoattachpoint="scrollboxNode" role="presentation" style="height: 721px;">
<div class="dojoxGridContent" dojoattachpoint="contentNode" hidefocus="hidefocus" role="presentation" style="height: 504px; width: 1900px;">
<div role="presentation" style="position: absolute; left: 0px; top: 0px;">
<div aria-selected="false" class="dojoxGridRow" role="row" style="">
<table border="0" cellpadding="0" cellspacing="0" class="dojoxGridRowTable" role="presentation" style="width: 1900px;">
<tbody>
<tr>
<td class="dojoxGridCell" idx="0" role="gridcell" style="display:none;width:100px;" tabindex="-1">
78126
</td>
<td class="dojoxGridCell" idx="1" role="gridcell" style="width:10%;" tabindex="-1">
Approved Plan
</td>
<td class="dojoxGridCell" idx="2" role="gridcell" style="width:10%;" tabindex="-1">
G-10
</td>
<td class="dojoxGridCell" idx="3" role="gridcell" style="width:40%;" tabindex="-1">
ROOF PLAN
</td>
</tr>
</tbody>
</table>
</div>"""
from bs4 import BeautifulSoup
soup = BeautifulSoup(source,"html.parser")
for article in soup.find_all('div', class_='dojoxGridContent'):
drawing_no = article.find('td', class_='dojoxGridCell', idx='3')
if drawing_no:
print(drawing_no.get_text())
please try below code. But in general if you pass in idx=3 it will only return one single element. If you want to extract text from multiple element you might want to use a more general identifier.
import lxml
from lxml import html
html_string = """
<div class="dojoxGridView" id="dojox_grid__View_1" role="presentation" style="width: 1900px; height: 721px; left: 1px; top: 0px;" widgetid="dojox_grid__View_1">
<input class="dojoxGridHiddenFocus" dojoattachpoint="hiddenFocusNode" role="presentation" type="checkbox"/>
<input class="dojoxGridHiddenFocus" role="presentation" type="checkbox"/>
<div class="dojoxGridScrollbox" dojoattachpoint="scrollboxNode" role="presentation" style="height: 721px;">
<div class="dojoxGridContent" dojoattachpoint="contentNode" hidefocus="hidefocus" role="presentation" style="height: 504px; width: 1900px;">
<div role="presentation" style="position: absolute; left: 0px; top: 0px;">
<div aria-selected="false" class="dojoxGridRow" role="row" style="">
<table border="0" cellpadding="0" cellspacing="0" class="dojoxGridRowTable" role="presentation" style="width: 1900px;">
<tbody>
<tr>
<td class="dojoxGridCell" idx="0" role="gridcell" style="display:none;width:100px;" tabindex="-1">
78126
</td>
<td class="dojoxGridCell" idx="1" role="gridcell" style="width:10%;" tabindex="-1">
Approved Plan
</td>
<td class="dojoxGridCell" idx="2" role="gridcell" style="width:10%;" tabindex="-1">
G-10
</td>
<td class="dojoxGridCell" idx="3" role="gridcell" style="width:40%;" tabindex="-1">
ROOF PLAN
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
"""
tree = html.fromstring(html_string)
ROOFPLAN = tree.xpath('//tbody/tr//td[#idx="3"]/text()')
print(''.join(ROOFPLAN).strip())
You can use the idx attribute and select by its value
print(soup.select_one("[idx='3']").text.strip())

how i can select data from a combo box and fires onchange command using VBA-excel

i want to select "56 - Hoyer (Suk / Rontec)" in the combo box and then fire the event that reloads the page using VBA excel, i can put the text on the combo box, but it doesnt load tha javascript attached to it (onchange event).
see image of the drop down / combo box here
below is the code i use in VBA to fill out the combobox with a constant value. but i cannot run the onchange event on html provided.
Call IE.document.getElementById("orders.carrier_number_txtSelectionDisplay").setAttribute("value", "56 - Hoyer (Suk / Rontec)")
Call IE.document.getElementById("orders.carrier_number_txtSelectionDisplay").setAttribute("value", "56 - Hoyer (Suk / Rontec)")
Set x = IE.document.getElementById(orders.carrier_number_txtSelectedValue)
x.Focus
x.FireEvent "onchange"
Below is the HTML code:
<td>
<div>
<span id="Descriptor.orders.carrier_number" class="dataentry-descriptor dataentry-descriptor-top" style="text-align:left;">Carrier</span>
</div>
<div class="dataentry-field-control" style="text-align:left;">
<div id="orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b" timerid="" querymethodname="GetSupplierCarriers">
<div id="orders.carrier_number_pnlSelectionDisplay" class="ffnet-combo-box dataentry-field required" style="width:180px;">
<table border="0" style="border-spacing: 0px; border-collapse: collapse; margin:0px;">
<colgroup>
<col style="width: 100%">
<col style="width: 30px; text-align: right;">
</colgroup>
<tbody>
<tr>
<td style="padding: 0px;">
<input name="orders.carrier_number$txtSelectionDisplay" type="text" id="orders.carrier_number_txtSelectionDisplay" class="dataentry-field required validate[required] required" isrequired="True" datatype="3"
onkeydown="javascript:return InputProcessKeyDown('orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b', event);" onfocus="javascript:return InputProcessOnFocus('orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b');
" style="width:150px;">
<input name="orders.carrier_number$txtSelectedValue" type="text" onchange="retrieveChildData("orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b","orders.loaded_driver_number_e5ba36ca-
aa0f-4f55-aa3e-c7cb342d0b0b"); retrieveChildData("orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b","orders.delivered_driver_number_e7747c68-df71-4774-9b04-
d897d1fd9833"); retrieveChildData("orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b","orders.vehicle_code_d3cc805c-e505-45c5-a351-98028439e34d"); retrieveChildData("orders.carrier_number_4b7bc829-
2760-4042-aab0-be8ccfb9541b","orders.tractor_number_089faa52-6810-4815-8f64-81eb201105a2"); UpdateDirtyBit(1);setTimeout('__doPostBack(\'orders.carrier_number$txtSelectedValue\',\'\')', 0)"
onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="orders.carrier_number_txtSelectedValue" datavaluefield="carrier_number" assembly="FFNET_CORE" funcname="OrderDispatch_DeleteOrderTrailer"
methodclass="CBL" hasautopostback="true" namespace="FBS" selectlistargs="{"SenderId":"orders.carrier_number","supplier_number":"139","RequiresParent":"True"}" style="display:none;">
</td>
<td>
<img id="orders.carrier_number_imgArrow" onclick="InputProcessOnFocus('orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b'); activeCB.toggleDropDown();" src="/ffnet/Images/DropDownListArrow.gif">
</td>
</tr>
</tbody>
</table>
</div>
<div id="orders.carrier_number_pnlDropDownList" class="ffnet-combo-box-ddlist" style="width:339px;">
<div id="orders.carrier_number_pnlDropDownRegion" class="ffnet-combo-box-ddregion" value="" style="width:339px;">
<table header="0" style="width:322px;" cellspacing="0" cellpadding="0">
<colgroup>
<col style="width:80px;">
<col style="width:210px;">
</colgroup>
<tbody>
<tr>
<th>Carrier Number</th>
<th>Name</th>
</tr>
</tbody>
</table>
<div id="orders.carrier_number_pnlDataRegion" class="ffnet-combo-box-data" style="width:339px;height:200px;">
<table style="width:322px;" onkeydown="javascript:return ProcessKeyDown(this, event);" tabindex="0" mode="combobox">
<colgroup>
<col style="width:80px;">
<col style="width:210px;">
</colgroup>
<tbody>
<tr id="orders.carrier_number_tr0" pk="1" text="1 - Armac Shipping" class="ffnet-combo-box-row-focus">
<td>1</td>
<td>Armac Shipping</td>
</tr>
<tr id="orders.carrier_number_tr1" pk="2" text="2 - IPCS Ltd">
<td>2</td>
<td>IPCS Ltd</td>
</tr>
<tr id="orders.carrier_number_tr23" pk="56" text="56 - Hoyer (Suk / Rontec)">
<td>56</td>
<td>Hoyer (Suk / Rontec)</td>
</tr>
</tbody>
</table>
</div>
<div id="orders.carrier_number_pnlPager" class="ffnet-combo-box-paging" title="Click for more records" onclick="RetrieveNextPage($("[id$='orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b']").get(0), false);
" recordcount="129">
1-30 of 129 results
</div>
</div>
</div>
</div>
<input type="hidden" name="orders.carrier_number_txtSelectedValue_hdnDirtyBit" id="orders.carrier_number_txtSelectedValue_hdnDirtyBit" value="0">
</div>

How to Scroll and Select/Doubleclick a listbox item?

I'm trying to get Intranet-web reports using VBA-Excel. How can I scroll to the item in a list and select or double-click it?
I located the item using ID of its parent-element and its own class and innertext values. I tried .click method in many ways, but without success.
Sub VBA_IE()
Dim IE As New SHDocVw.InternetExplorerMedium
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLDiv As MSHTML.IHTMLElement
Dim HTMLDivs As MSHTML.IHTMLElementCollection
'
'Here is IE object set and the page loaded
'
Set HTMLDoc = IE.document
Set HTMLDivs = HTMLDoc.getElementById "id_mstr104ListContainer").getElementsByTagName("div")
For Each HTMLDiv In HTMLDivs
If HTMLDiv.getAttribute("title") = "Fourth Center" Then
HTMLDiv.Focus
HTMLDiv.click
'wait-routines
Application.Wait Now + TimeValue("00:00:05")
Exit For
Else
End If
Next HTMLDiv
IE.Quit
Set IE = Nothing
End Sub
Part of page's source (extended on Feb 20 2019):
<div style="display: block;" class="mstrPromptQuestion" id="id_mstr80">
<span class="">
<div class="mstrPromptQuestionTitleBar">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" valign="middle">
<span class="mstrPromptQuestionTitleBarIndex" style="display: inline;">1.</span>
<span class="mstrPromptQuestionTitleBarTitle">Delivery Source</span>
<span class="mstrPromptQuestionTitleBarRequired" title="(Required)">(Required)</span>
</td>
<td width="1%" align="right" valign="middle">
<img src="../images/1ptrans.gif" align="absmiddle" style="display: none" class="mstrPromptQuestionBackToTopImg" title="Back to top" onclick="mstr.behaviors.PromptQuestion.onClickBackToTop('id_mstr80')">
</td>
</tr>
</tbody>
</table>
</div>
<table cellspacing="0" cellpadding="0" class="mstrPromptQuestionInfoTable">
<tbody>
<tr>
<td class="mstrPromptQuestionInfoCellLeft">
<div class="mstrPromptQuestionMeaning" style="display: block;">Select items for Delivery Source</div>
<div class="mstrPromptQuestionInstructions" style="display: none;"></div>
<div class="mstrPromptQuestionMessage" style="display: none;"></div>
</td>
<td class="mstrPromptQuestionInfoCellRight">
<span class="mstrPlaceholder" name="saveAnswerView" id="id_mstr81"></span>
</td>
</tr>
</tbody>
</table>
<div class="mstrPromptQuestionContents">
<table cellspacing="0" cellpadding="0" class="mstrPromptQuestionSimpleAnswerViewTitle" style="display: none;">
<tbody>
<tr>
<td class="mstrPromptQuestionSimpleAnswerViewTitleCellRadio">
<input value="0" name="id_mstr80_radio" onmousedown="mstr.behaviors.PromptQuestion.onClickRadio('id_mstr80', false)" id="id_mstr80_radio_simpleAnswerView" type="radio" checked="true">
</td>
<td class="mstrPromptQuestionSimpleAnswerViewTitleCellText">
<label for="id_mstr80_radio_simpleAnswerView">Your selection:</label>
</td>
</tr>
</tbody>
</table>
<div style="padding-left: 0px;" class="mstrPromptQuestionSimpleAnswerView" onmousedown="this.previousSibling.rows[0].cells[0].childNodes[0].checked = true; mstr.behaviors.PromptQuestion.onClickRadio('id_mstr80', false)">
<table cellspacing="0" style="display: table;" cellpadding="0" class="mstrListCart" id="id_mstr84">
<colgroup><col class="mstrListCartLeftCol"><col class="mstrListCartButtonCol"><col class="mstrListCartRightCol"><col class="mstrListCartButtonCol"></colgroup>
<tbody>
<tr>
<td class="mstrListCartRowPathView" style="width:100%;" colspan="4">
<table cellspacing="0" cellpadding="0" class="mstrListCartTablePathView" style="display: none;">
<tbody>
<tr>
<td class="mstrListCartCellPathView">
<span class="mstrPlaceholder" name="pathView" id="id_mstr87"></span>
</td>
<td class="mstrListCartCellPathUpButton">
<span class="mstrPlaceholder" name="pathUpButton" id="id_mstr88"></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="mstrListCartCellSearchView" style="width:100%;" colspan="4">
<div title="" class="mstrSearchField" id="id_mstr99" style="display: block;">
<table cellspacing="0" cellpadding="0" class="mstrSearchFieldTable">
<tbody>
<tr>
<td class="mstrSearchFieldSearchBox">
<div title="" class="mstrTextBoxWithIcon" id="id_mstr102" style="display: block;">
<div class="mstrTextBoxWithIconCaption">
<label for="id_mstr102_txt">Search for:</label>
</div>
<table cellspacing="0" cellpadding="0" class="mstrTextBoxWithIconTable">
<tbody>
<tr>
<td class="mstrTextBoxWithIconCellInput">
<div>
<input maxlength="" onclick="if (mstr.utils.ISW3C) {this.focus();}" onkeypress="return mstr.behaviors.TextBoxWithIcon.onkeypress(arguments[0], self, 'id_mstr102', this.value)" name="id_mstr102_txt" style="background-color: rgb(255, 255, 255);" id="id_mstr102_txt" size="" type="text">
</div>
</td>
<td class="mstrTextBoxWithIconCellIcon">
<div class="mstrToolButtonRoundedRight">
<input type="button" title="Search" onmouseout="mstr.behaviors.ToolButtonRounded.unhover(this.parentNode)" style="background-position: left center; cursor: pointer;" class="mstrBGIcon_tbSearch" src="../images/1ptrans.gif" onmouseover="mstr.behaviors.ToolButtonRounded.hover(this.parentNode)" onclick="mstr.behaviors.TextBoxWithIcon.fire('id_mstr102', this.parentNode.parentNode.previousSibling.childNodes[0].childNodes[0].value);return false;">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td class="mstrSearchFieldMatchCaseBox">
<div class="mstrCheckBox" style="display: block;" id="id_mstr103">
<input type="checkbox" id="id_mstr103_input" onclick="mstr.$obj('id_mstr103').getModel() && mstr.$obj('id_mstr103').getModel().set('searchMatchCase', this.checked); mstr.$obj('id_mstr103').fireCommands(null, this.checked);">
<label title="" for="id_mstr103_input">Match case</label>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td class="mstrListCartCellAvailableView">
<table cellspacing="0" cellpadding="0" style="table-layout: auto; width: 100%;">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" title="" class="mstrListBlock" id="id_mstr104" style="display: table; width: 100%;">
<tbody>
<tr>
<td class="mstrListBlockCell">
<span class="">
<div class="mstrListBlockCaption" style="display: block;">Available:</div>
<div class="mstrListBlockHeader" style="display: none">
<span class="mstrPlaceholder" name="headerView" id="id_mstr105"></span>
</div>
<div style="width: auto; height: 150px;" class="mstrListBlockContents" id="ListBlockContents_id_mstr104">
<div oncontextmenu="return mstr.behaviors.Generic.oncontextmenu(arguments[0], self, 'id_mstr104');" onmouseup="try{mstr.$obj('id_mstr104').focus();}catch(localerr){}; return mstr.behaviors.Generic.clearBrowserHighlights(self)" onmousedown="var retVal = mstr.behaviors.ListView.onmousedown(arguments[0], self, 'id_mstr104'); try{mstr.$obj('id_mstr104').focus();}catch(localerr){}; return retVal" ondblclick="return mstr.behaviors.ListView.ondblclick(arguments[0], self, 'id_mstr104')" class="mstrListBlockListContainer" id="id_mstr104ListContainer" style="display: block; height: 80px;">
<div class="mstrListBlockItemSelected" title="First Center">
<div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">First</div>
</div>
<div class="mstrListBlockItem" title="Second Center">
<div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">Second Center</div>
</div>
<div class="mstrListBlockItem" title="Third Added Center">
<div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">Third Added Center</div>
</div>
<div class="mstrListBlockItem" title="Fourth Center">
<div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">Fourth Center</div>
</div>
</div>
<div class="mstrListBlockReadyState" style="display: none;"></div>
<div class="mstrListBlockMessageSection" style="display: none;">
<div class="mstrListBlockMessage"></div>
</div>
</div>
<a title="" href="#" onkeydown="return mstr.$obj('id_mstr104').onkeydown(arguments[0], self);" onkeypress="return mstr.$obj('id_mstr104').onkeypress(arguments[0], self);" class="mstrListBlockTabStop" id="id_mstr104TabStop">
<div></div>
</a>
</span>
</td>
</tr>
</tbody>
</table>
</td>
<td class="mstrListCartCellAddRemoveButtons">
<div>
<div class="mstrToolButtonRounded" id="id_mstr106" style="display: block;">
<img title="Add" onmouseout="mstr.behaviors.ToolButtonRounded.unhover(this.parentNode)" style="background-position: left center; cursor: pointer;" class="mstrBGIcon_tbAdd" src="../images/1ptrans.gif" onmouseover="mstr.behaviors.ToolButtonRounded.hover(this.parentNode)" align="absmiddle" onclick="var v = mstr.$obj('id_mstr106'); return (v.get('enabled')) ? mstr.$obj('id_mstr106').fireCommands() : false;">
</div>
</div>
<div>
<div class="mstrToolButtonRounded" id="id_mstr107" style="display: block;">
<img title="Add All" onmouseout="mstr.behaviors.ToolButtonRounded.unhover(this.parentNode)" style="background-position: left center; cursor: pointer;" class="mstrBGIcon_tbAddAll" src="../images/1ptrans.gif" onmouseover="mstr.behaviors.ToolButtonRounded.hover(this.parentNode)" align="absmiddle" onclick="var v = mstr.$obj('id_mstr107'); return (v.get('enabled')) ? mstr.$obj('id_mstr107').fireCommands() : false;">
</div>
</div>
<div style="height: 11px; width: 1px; overflow: hidden"></div>
<div>
<div class="mstrToolButtonRounded" id="id_mstr108" style="display: block; background-position: left center;">
<img title="Remove" onmouseout="mstr.behaviors.ToolButtonRounded.unhover(this.parentNode)" style="background-position: right center; cursor: default;" class="mstrBGIcon_tbRemove" src="../images/1ptrans.gif" onmouseover="mstr.behaviors.ToolButtonRounded.hover(this.parentNode)" align="absmiddle" onclick="var v = mstr.$obj('id_mstr108'); return (v.get('enabled')) ? mstr.$obj('id_mstr108').fireCommands() : false;">
</div>
</div>
<div>
<div class="mstrToolButtonRounded" id="id_mstr109" style="display: block; background-position: left center;">
<img title="Remove All" onmouseout="mstr.behaviors.ToolButtonRounded.unhover(this.parentNode)" style="background-position: right center; cursor: default;" class="mstrBGIcon_tbRemoveAll" src="../images/1ptrans.gif" onmouseover="mstr.behaviors.ToolButtonRounded.hover(this.parentNode)" align="absmiddle" onclick="var v = mstr.$obj('id_mstr109'); return (v.get('enabled')) ? mstr.$obj('id_mstr109').fireCommands() : false;">
</div>
</div>
</td>
<td class="mstrListCartCellSelectedView">
<table cellspacing="0" cellpadding="0" style="table-layout: auto; width: 100%;">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="0" title="" class="mstrListBlock" id="id_mstr110" style="display: table; width: 100%;">
<tbody>
<tr>
<td class="mstrListBlockCell"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<span class="">
<div class="mstrListBlockCaption" style="display: block;">Selected:</div>
<div class="mstrListBlockHeader" style="display: none">
<span class="mstrPlaceholder" name="headerView" id="id_mstr111"></span>
</div>
<div style="width: auto; height: 150px;" class="mstrListBlockContents" id="ListBlockContents_id_mstr110">
<div oncontextmenu="return mstr.behaviors.Generic.oncontextmenu(arguments[0], self, 'id_mstr110');" onmouseup="try{mstr.$obj('id_mstr110').focus();}catch(localerr){}; return mstr.behaviors.Generic.clearBrowserHighlights(self)" onmousedown="var retVal = mstr.behaviors.ListView.onmousedown(arguments[0], self, 'id_mstr110'); try{mstr.$obj('id_mstr110').focus();}catch(localerr){}; return retVal" ondblclick="return mstr.behaviors.ListView.ondblclick(arguments[0], self, 'id_mstr110')" class="mstrListBlockListContainer" id="id_mstr110ListContainer" style="display: none; height: auto;"></div>
<div class="mstrListBlockReadyState" style="display: none;"></div>
<div class="mstrListBlockMessageSection" style="display: block;">
<div class="mstrListBlockMessage">(none)</div>
</div>
</div>
<a title="" href="#" onkeydown="return mstr.$obj('id_mstr110').onkeydown(arguments[0], self);" onkeypress="return mstr.$obj('id_mstr110').onkeypress(arguments[0], self);" class="mstrListBlockTabStop" id="id_mstr110TabStop">
<div></div>
</a>
</span>
</td>
<td class="mstrListCartCellUpDownButtons">
<span class="mstrPlaceholder" name="upButton" id="id_mstr96"></span>
<span class="mstrPlaceholder" name="downButton" id="id_mstr97"></span>
</td>
</tr>
<tr>
<td class="mstrListCartCellFetchView" colspan="4">
<table title="" cellspacing="0" style="display: table;" cellpadding="0" class="mstrFetchControl" id="id_mstr112">
<tbody>
<tr>
<td>
<img title="First page" src="../images/1ptrans.gif" align="absmiddle" onclick="mstr.behaviors.FetchControl.fireFetchCommand('id_mstr112', 'FetchFirst')" class="mstrBGIcon_fetchFirstDisabled " style="display: none;">
</td>
<td>
<img title="Previous Page" src="../images/1ptrans.gif" align="absmiddle" onclick="mstr.behaviors.FetchControl.fireFetchCommand('id_mstr112', 'FetchPrevious')" class="mstrBGIcon_fetchPreviousDisabled " style="display: none;">
</td>
<td class="mstrFetchControlCellText">
<div onmouseout="this.className = this.className.replace(/Hover/,'')" onmousedown="mstr.behaviors.FetchControl.on_mousedown('id_mstr112')" class="mstrFetchControlText" onmouseover="if (!this.disabled) this.className += 'Hover'">1 - 4 of 4</div>
</td>
<td>
<img title="Next page" src="../images/1ptrans.gif" align="absmiddle" onclick="mstr.behaviors.FetchControl.fireFetchCommand('id_mstr112', 'FetchNext')" class="mstrBGIcon_fetchNextDisabled " style="display: none;">
</td>
<td>
<img title="Last page" src="../images/1ptrans.gif" align="absmiddle" onclick="mstr.behaviors.FetchControl.fireFetchCommand('id_mstr112', 'FetchLast')" class="mstrBGIcon_fetchLastDisabled " style="display: none;">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<table cellspacing="0" cellpadding="0" class="mstrPromptQuestionComplexAnswerViewTitle" style="display: none;">
<tbody>
<tr>
<td class="mstrPromptQuestionComplexAnswerViewTitleCellRadio">
<input value="1" name="id_mstr80_radio" onmousedown="mstr.behaviors.PromptQuestion.onClickRadio('id_mstr80', true)" id="id_mstr80_radio_complexAnswerView" type="radio">
</td>
<td class="mstrPromptQuestionComplexAnswerViewTitleCellText">
<label for="id_mstr80_radio_complexAnswerView">The default selection is:</label>
</td>
</tr>
</tbody>
</table>
<div style="padding-left: 23px; display: none;" class="mstrPromptQuestionComplexAnswerView" onmousedown="this.previousSibling.rows[0].cells[0].childNodes[0].checked = true; mstr.behaviors.PromptQuestion.onClickRadio('id_mstr80', true)">
<div title="" class="mstrTextDiv" style="display: block;" id="id_mstr113">
<div class="mstrTextDivCaption"></div>
<div class="mstrTextDivValue"></div>
</div>
</div>
</div>
</span>
</div>
VBA-code just passes through the command line like nothing happened, or reports an error that the method is not applicable to the element.
Looks like you will need events to be fired but here are two things to try
ie.document.parentWindow.execScript "document.querySelector('[title^=Fourth]').setAttribute('class','mstrListBlockItemSelected');"
And
ie.document.querySelector("[title='Fourth Center']").FireEvent "ondblclick"

Find label name which doesn't contain input immediately from a table

I am having a table which contains multiple td/tr.
My problem is label which i want to get doesn't contains input immediately neither that label has any attributes property.
I want to get "Countries of Permanent Residence" and Dates which are in span but doesn't have any properties that span is in div that too doesn't contains any property.
I tried with
formElement[input[name="icims_gh_Permanent_Country_Residence"]]
But don't know how to get associate label.
Html looks like:
<div style="margin:0px">
<table style="width:100%" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px"> Countries of Permanent Residence (list all) </span>
</div>
</td>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px"> Dates </span>
</div>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<div style="margin:0px">
<div>
<input type="hidden" name="icims_gh_Permanent_Country_Residence" value="1">
<a name="0.1_icims_ga_Permanent_Country_Residence"></a>
<div>
<table style="width:100%;border:0px">
<tbody>
<tr>
<td>
<table style="width:100%" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px">
<input type="text" name="icims_0_permResidenceCountry"> </span>
</div>
</td>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px">
<input type="text" name="icims_0_permResidenceCountryDates"> </span>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>

Resources