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

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>

Related

Selenium Python select and click multiple checkbox elements by input type

Trying to select and click multiple checkboxes on a page. they don't have a class, ID or names that match. All they have in common is their input type (checkbox). I'm able to select individual checkboxes using XPATH but its not practical as there's at least 100 checkboxes on the page.
Here's a section of the HTML. I've been testing this code on an off-line version of the site.
<body>
<tbody>
<tr>
<td class="borderBot"><b>Activity</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="33%">
<input type="checkbox" name="competency1Activity" value="1" />
Plan (ie Interpreted diag etc)
</td>
<td width="33%">
<input type="checkbox" name="competency1Activity" value="2" />
Carry Out (ie conducted work)
</td>
<td width="33%">
<input type="checkbox" name="competency1Activity" value="4" />
Complete (ie Compliance etc)
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="borderBot"><b>Supervision</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="33%">
<input
type="checkbox"
name="competency1Supervision"
value="1"
/>
Direct
</td>
<td width="33%">
<input
type="checkbox"
name="competency1Supervision"
value="2"
/>
General
</td>
<td width="33%">
<input
type="checkbox"
name="competency1Supervision"
value="4"
/>
Broad
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="borderBot"><b>Support</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="33%">
<input type="checkbox" name="competency1Support" value="1" />
Constant
</td>
<td width="33%">
<input type="checkbox" name="competency1Support" value="2" />
Intermittent
</td>
<td width="33%">
<input type="checkbox" name="competency1Support" value="4" />
Minimal
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="borderBot"><b>Materials</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="1" />
Insulation failure
</td>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="2" />
Incorrect connections
</td>
</tr>
<tr>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="4" />
Circuits-wiring; eg. open short
</td>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="8" />
Unsafe condition
</td>
</tr>
<tr>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="16"
/>
Apparatus/component failure
</td>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="32"
/>
Related mechanical failure
</td>
</tr>
<tr>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="64"
/>
Read/interpret drawings/plans
</td>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="128"
/>
Other elec app and circuit faults
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<input
type="hidden"
id="competency1ExtendedCount"
name="competency1ExtendedCount"
value="8"
/>
</tbody>
</body>
Try 1 - this selects and clicks the first checkbox but none of the others
checkboxes = driver.find_element(By.CSS_SELECTOR, "input[type='checkbox']").click()
Try 2 - Thought this would work but I cant get the syntax right
checkboxes = driver.find_element(By.CSS_SELECTOR, "input[type='checkbox']")
for checkbox in checkboxes:
checkboxes.click()
time.sleep(.3)
Try 3 - able to select first checkbox (of 3) with this name
checkboxes = driver.find_element("name", "competency1Ativity").click()
find_element() will return only the first matching element, where as you need to identify all of them. So you need to use find_elements() method.
Solution
You can identify all the checkbox and store the elements within a list and then click on them one by one using either of the following locator strategies:
Using CSS_SELECTOR:
from selenium.webdriver.common.by import By
checkboxes = driver.find_elements(By.CSS_SELECTOR, "td input[type='checkbox']")
for checkbox in checkboxes:
checkbox.click()
Using XPATH:
from selenium.webdriver.common.by import By
checkboxes = driver.find_elements(By.XPATH, "//td//input[#type='checkbox']")
for checkbox in checkboxes:
checkbox.click()
Your option 2 was nearly correct, however it should have been find_elements() not find_element()
Since find_element() just returns an webelement where as find_elements() returns list of elements.
code:
checkboxes = driver.find_elements(By.CSS_SELECTOR, "input[type='checkbox']")
for checkbox in checkboxes:
checkbox.click()
time.sleep(0.5)

Retrieve 'tr' by text of children

I want to select a tr by the text it contains, including the text of the children.
My html is as follows:
<table>
<tbody>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl21_Label4">Sanskrit</span>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl21_Label2">0655-0700 </span>
</td>
<td>
<a id="ctl00_ContentPlaceHolder1_GridView1_ctl21_LinkButtonDownloadPdf" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1$ctl21$LinkButtonDownloadPdf','')" style="color: Navy;
font-weight: bold;">Download</a>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl21_Label3">24 October</span>
</td>
</tr>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl22_Label4">Sanskrit</span>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl22_Label2">1810-1815 </span>
</td>
<td>
<a id="ctl00_ContentPlaceHolder1_GridView1_ctl22_LinkButtonDownloadPdf" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1$ctl22$LinkButtonDownloadPdf','')" style="color: Navy;
font-weight: bold;">Download</a>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl22_Label3">23 October</span>
</td>
</tr>
</tbody>
</table>
I load it thus _soup = soup(html, "html.parser").
If i run _soup.find("span", text="Sanskrit").parent.parent.text then I get the result '\n\nSanskrit\n\n\n0655-0700 \n\n\nDownload\n\n\n24 October\n\n'
but if i run print(_soup.find("tr", text='\n\nSanskrit\n\n\n0655-0700 \n\n\nDownload\n\n\n24 October\n\n'))
i get None
Issue here is that text needs an exact match - You could regex or use css selectors and :-soup-contains():
soup.select('tr:has(:-soup-contains("Sanskrit"))')
or based on comment, check if your text is in <tr>s text:
for row in soup.select('tr'):
if '\n\nSanskrit\n\n\n0655-0700 \n\n\nDownload\n\n\n24 October\n\n' in row.text:
print(row)
Example
from bs4 import BeautifulSoup
html = '''
<table>
<tbody>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl21_Label4">Sanskrit</span>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl21_Label2">0655-0700 </span>
</td>
<td>
<a id="ctl00_ContentPlaceHolder1_GridView1_ctl21_LinkButtonDownloadPdf" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1$ctl21$LinkButtonDownloadPdf','')" style="color: Navy;
font-weight: bold;">Download</a>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl21_Label3">24 October</span>
</td>
</tr>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl22_Label4">Sanskrit</span>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl22_Label2">1810-1815 </span>
</td>
<td>
<a id="ctl00_ContentPlaceHolder1_GridView1_ctl22_LinkButtonDownloadPdf" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1$ctl22$LinkButtonDownloadPdf','')" style="color: Navy;
font-weight: bold;">Download</a>
</td>
<td>
<span id="ctl00_ContentPlaceHolder1_GridView1_ctl22_Label3">23 October</span>
</td>
</tr>
</tbody>
</table>'''
soup = BeautifulSoup(html)
soup.select('tr:has(:-soup-contains("Sanskrit"))')

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>

Layout for table using Bootstrap 4.2 not aligning as expected

In the process of moving from Bootstrap 3 to Bootstrap 4.2. I have a table inside a Ajax modal screen. Here is the code snippet:
<div class="card-body">
<div class="row">
<table class="table table-hover table-responsive-lg">
<thead>
<tr>
<td class="text-center col-sm-3"><strong>ACTIVITY</strong></td>
<td class="text-center col-sm-3"><strong>QTY</strong></td>
<td class="text-center col-sm-3"><strong>RATE</strong></td>
<td class="text-center col-sm-3"><strong>AMOUNT</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Closing Service" CssClass="form-con"></asp:Label></td>
<td class="text-center ">
<asp:TextBox ID="txtClosing_QTY" runat="server" CssClass="form-control"></asp:TextBox></td>
<td class="text-center ">
<asp:TextBox ID="txtClosing_Rate" runat="server" CssClass="form-control"></asp:TextBox></td>
<td class="text-center ">
<asp:TextBox ID="txtClosing_Total" runat="server" CssClass="form-control" ClientIDMode="Static"></asp:TextBox></td>
</tr>
</tbody>
</table>
</div>
</div>
In my system the columns showing QTY is too small to see the full number, even the number 1.
UPDATE
I changed the headers to col-sm-4 and the results are much the same. Here is an image of the outcome:
UPDATE 2
Suggested adding ROW class to the <tr> results in:
You can try adding class="row" to each tr instead of to the outside div
Example:
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css">
</head>
<body>
<div style="width: 572px;">
<div class="card-body">
<div class="">
<table class="table table-hover table-responsive-lg">
<thead>
<tr class="row">
<td class="text-center col-sm-3"><strong>ACTIVITY</strong></td>
<td class="text-center col-sm-3"><strong>QTY</strong></td>
<td class="text-center col-sm-3"><strong>RATE</strong></td>
<td class="text-center col-sm-3"><strong>AMOUNT</strong></td>
</tr>
</thead>
<tbody>
<tr class="row">
<td class="col-sm-3 text-center "><asp:Label ID="Label1" runat="server" Text="Closing Service" CssClass="form-con"></asp:Label></td>
<td class="text-center col-sm-3">
<asp:TextBox ID="txtClosing_QTY" runat="server" CssClass="form-control"></asp:TextBox></td>
<td class="text-center col-sm-3">
<asp:TextBox ID="txtClosing_Rate" runat="server" CssClass="form-control"></asp:TextBox></td>
<td class="text-center col-sm-3">
<asp:TextBox ID="txtClosing_Total" runat="server" CssClass="form-control" ClientIDMode="Static"></asp:TextBox></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
I wanted to close this out with a solution that worked for me. It was simple to fix. In the <thead> section of the table I removed the col-sm-3 tag and the table behaved as expected.
Thanks everyone!

MODX: display elements in groups by two with wrapper for every group

Imagine situation when you need to have output like this
<table>
<tr class="row">
<td class="cell">First resource</td>
<td class="cell">Second resource</td>
</tr>
<tr class="row">
<td class="cell">Third resource</td>
<td class="cell">Fourth resource</td>
</tr>
<tr class="row">
<td class="cell">Fifth resource</td>
<td class="cell">Sixth resource</td>
</tr>
</table>
or like this
<div class="container">
<div class="row"><!--groups-->
<div class="col-md-6">
First resource
</div>
<div class="col-md-6">
Second resource
</div>
<div class="clearfix"> </div>
</div>
<div class="row"><!--group-->
<div class="col-md-6">
Third resource
</div>
<div class="col-md-6">
Fourth resource
</div>
<div class="clearfix"> </div>
</div>
<div><!--group-->
...
</div>
...
...
</div>
As for me this structures are similar for my purpose. I was looking for examples of the usage of placeholders, but do not get it. Please write the example with getResources or PDOTools or similar.
[[pdoResources?
&parents=`0`
&depth=`1`
&tplFirst=`tplFirst`
&tpl=`tpl`
&tplOdd=`tplOdd`
&tplLast=`tplLast`
&tplWrapper=`tplWrapper`
]]
tplFirst
<tr class="row">
<td class="cell">[[+pagetitle]]</td>
tpl
<td class="cell">[[+pagetitle]]</td>
tplOdd
<td class="cell">[[+pagetitle]]</td>
</tr>
<tr class="row">
tplLast
<td class="cell">[[+pagetitle]]</td>
</tr>
tplWrapper
<table>
[[+output]]
</table>

Resources