How to locate a name using xpath out of three items? - selenium

I've written an xpath to locate a name from th tag but the thing is there are three items attached within a "th" tag separated by "br" tag. How to locate only the first item which is in this case the name among three? Here is what I tried with:
//td[#class='data']/table//th
Elements within the items are:
<td class="data" valign="top" nowrap="">
<table width="350">
<tbody><tr>
<td valign="top" nowrap="">Owner Name &<br>Mailing Address:</td>
<th align="left" valign="top" nowrap="">
<!-- ---------- OWNER NAME ---------- -->
PADILLA ISAI & JOSEFINA<br>
<!-- ---------- MAILING ADDRESS ---------- -->
<!-- ---------- MAILING ADDRESS (MAIL TO) ---------- -->
<!-- ---------- MAILING ADDRESS (ADDR1 AND ADDR2) ---------- -->
8227 FINDLAY ST<br>
<!--
------------------------------------------------
'RA 09/11/2012:
Changed order of Owner / Address to :
Owner Name(s)
MailTo
Addr_1
Addr_2
City
State
Zip
Country
------------------------------------------------
8227 FINDLAY ST
------------------------------------------------
-->
<!-- ---------- MAILING ADDRESS (CITY-STATE-ZIP OR COUNTRY)---------- -->
HOUSTON TX 77017-2328<br>
<!--<br />-->
</th>
</tr>
</tbody></table>
</td>
With my expression the result I'm getting is:
DURAN FRANCISCO & AURORA
4010 BALMORHEA AVE
HOUSTON TX 77039-2510
But I expect to get only:
DURAN FRANCISCO & AURORA
In general cases I would probably go for:
//td[#class='data']/table//th/text()[1]
But, selenium doesn't support text indexing either. What can I do to get the name only from the th tag?

Try below code and let me know in case it won't return expected result:
element = driver.find_element_by_xpath("//td[#class='data']/table//th")
print(driver.execute_script("return arguments[0].childNodes[2].textContent", element).strip())

I have the following way to execute the xpath which doesn't supported by selenium directly :
JavascriptExecutor js = (JavascriptExecutor)driver;
Object message = js.executeScript("var value = document.evaluate(\"//td[#class='data']/table//th/text()[1]\",document, null, XPathResult.STRING_TYPE, null ); return value.stringValue;");
System.out.println(message.toString());
Still having issue let me know :)
Get more details from this answer

Related

Pivot table with counts - Oracle SQL

I have this table:
table1
id e_nm val count
2572 Fruit Date 20180115 13
2572 Fruit Date 20180504 21
2573 Salad Date ABC 50
2574 Test Date 20181115 14
2574 Test Date 19991001 29
This table has all the distinct values present for each e_nm (element names) and their counts. This table has thousands of values available with more than 500 element names.
Is there a way I am able to visualise it like the following using Pivot:
id_2572 id_2572_e_nm id_2573 id_2573_e_nm id_2574 id_2574_e_nm
20180115 Fruit Date ABC Salad Date 20181115 Test Date
20180504 Fruit Date 19991001 Test Date
Please note the table column needs to be generated dynamically by reading id from table1.
Although not exactly as you pictured it, I have come up with a solution. Basically you will need to create a new column in the source table named unique id. This is the unique identifier under which you will be pivoting the table.
After that, you will need to use the following query to get the nearly desired output:
SELECT * FROM
(
SELECT
unique_id,
e_nm,
val
FROM table1
)
PIVOT
(
listagg(val) within group (order by null) as id, listagg(e_nm) within group (order by null) as id_e_nm
FOR e_nm IN ('Fruit Date','Salad Date','Test Date')
)
This will give you the following output:
body {
margin: 0;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 20px;
color: #333;
background-color: #fff;
}
<table class="results table table-bordered table-striped">
<tbody>
<tr>
<th>UNIQUE_ID</th>
<th>'Fruit Date'_ID</th>
<th>'Fruit Date'_ID_E_NM</th>
<th>'Salad Date'_ID</th>
<th>'Salad Date'_ID_E_NM</th>
<th>'Test Date'_ID</th>
<th>'Test Date'_ID_E_NM</th>
</tr>
<tr>
<td>1</td>
<td>20180115</td>
<td>Fruit Date</td>
<td>ABC</td>
<td>Salad Date</td>
<td>20181115</td>
<td>Test Date</td>
</tr>
<tr>
<td>2</td>
<td>20180504</td>
<td>Fruit Date</td>
<td>(null)</td>
<td>(null)</td>
<td>19991001</td>
<td>Test Date</td>
</tr>
</tbody>
</table>
Here is the link to the SQL Fiddle query I created to answer your question.
Hope this points you to the right direction :)

SQL - return rows with a duplicate value, where one row in each group has a certain attribute and not another

I am a SQL novice at best - appreciate any help on this answer. It's specific to the program MediaMonkey, but more broadly applicable I think since MediaMonkey's database is I believe SQLite 3. The table I'm querying is called Songs and all the columns I'm referencing are in this table.
I am using the Custom4 field in MediaMonkey to store a song's Work ID from Musicbrainz, and the Custom5 field to store the AcoustID. I'm trying to create a playlist of cover / alternate / live versions of songs that I've rated 5 stars, but where the 5 star song is not a classical work or a jazz recording (I use the Grouping field (GroupDesc) to indicate if a track is classical or jazz).
Parameters for the SQL query need to be something like this:
Same Work ID as a 5 star recording (Rating = 100), where the Grouping
of the 5 star recording is not 'Classical' or 'Jazz' (I am OK with
classical or jazz covers of 5 star popular works)
Different AcoustID from any 5 star recording (eliminate duplicate
recordings)
Rating < 5 stars (I don't want to include the 5 star songs
themselves)
I cobbled together the following SQL query from some examples I found:
Songs.Custom4 IN (SELECT Custom4 FROM Songs GROUP BY Custom4 HAVING Count(*) > 1 AND Max(Rating) > 99 AND Custom4 <> '' AND GroupDesc <> 'Classical' AND GroupDesc <> 'Jazz')
What this appears to include is the following:
Same WorkID as a 5 star recording
Classical or jazz tracks only if the classical or jazz track is rated
5 stars and there is another track with the same Work ID that is not
classical or jazz, or if the classical or jazz track has the same
Work ID as a 5 star recording that is not classical or jazz
Includes duplicates of the 5 star recording, and includes the 5 star
recordings themselves
Somehow then I need to filter out the 5 star classical or jazz tracks and the tracks that have the same Work IDs as those tracks, and I need to exclude the duplicates and the 5 star recordings.
Let's say you have a table like this:
<table class="blueTable">
<thead>
<tr>
<th> Song</th>
<th>Grouping</th>
<th>Rating</th>
<th>Work ID</th>
<th>AcoustID</th>
</tr>
</thead>
<tbody>
<tr>
<td>A1</td>
<td>Classical </td>
<td>100 </td>
<td>a12 </td>
<td>b12 </td>
</tr>
<tr>
<td>A2</td>
<td>Jazz </td>
<td>100 </td>
<td>a21 </td>
<td>b21 </td>
</tr>
<tr>
<td>A3</td>
<td> NULL</td>
<td>100 </td>
<td>a31 </td>
<td>b31 </td>
</tr>
<tr>
<td>A4</td>
<td>NULL </td>
<td>NULL </td>
<td>a12 </td>
<td>b41 </td>
</tr>
<tr>
<td>A5</td>
<td>NULL </td>
<td>NULL </td>
<td>a31 </td>
<td>b31 </td>
</tr>
<tr>
<td>A6</td>
<td>Classical </td>
<td>NULL </td>
<td>a31 </td>
<td>b61 </td>
</tr>
<tr>
<td>A7</td>
<td>NULL </td>
<td>NULL </td>
<td>a31 </td>
<td>b71 </td>
</tr>
</tbody>
</table>
I'd want my query to include the following songs: A6, A7
Here's the logic: A1 and A2 would be excluded since they are Classical and Jazz tracks and are not covers of a popular song with a rating of 100. A3 would be excluded since it has a rating of 100. A4 would be excluded since it's a popular cover of a Classical track that is rated 100. A5 would be excluded since it's a duplicate of A3. A6 is included - it's a Classical cover of A3. A7 is included - it's a cover of A3.

Is there a way to colspan a table header with GitHub flavored markdown?

HTML allows extending a table's header row across multiple columns using colspan:
<table>
<tr><th colspan=2>Logical Operators</th></tr>
<tr><td>&&</td><td>Logical and</td></tr>
<tr><td>||</td><td>Logical or</td></tr>
<tr><td>!</td><td>Logical not</td></tr>
<tr><td>? :</td><td>Logical ternary</td></tr>
</table>
On GitHub, when this HTML is rendered in a readme.md file it looks like this:
...but using markdown syntax to create a table, I can't span the table's header row across columns, e.g. I can only split up the header text:
| Logical | Operators |
|:---:| --- |
| `&&` | Logical and |
| `\|\|` | Logical or |
| `!` | Logical not |
| `? :` | Logical ternary |
...and rendering the GFM table on GitHub looks like:
I tried emulating this solution for using colspan in the table's data rows, but I could not get it to work with the header row. Is there a way to span the GFM table's header row across more than one column with GitHub flavored Markdown?
I've posted the question to the folks at the GH MD repo.
I did it this way in order to generate a table with 5 columns with headers spanning respectively over 3 and 2 columns:
<table>
<tr>
<td colspan=3>a <td colspan=2>b
<tr>
<td colspan=1>col1 <td colspan=1>col2 <td colspan=1>col3<td colspan=1>col4 <td colspan=1>col5
</table>
My two cents.

Insert a varchar column value into another varchar column after few desired words

I have a table named ClinicalDocuments which has a column named vReportText and it saves soap text of a lot of components. Now there is another table named TreatmentOrders with a column vSoapText which contains the soap text of order component.
I want to write a SP which will update soap text of order component in ReportText of clinical documents just after heading of Treatment Order is. I know it will involve some string manupulation to determine the exact position after heading to insert value but i can't figure out how exactly it is possible.
here is what vReportText's sample data is
<table class="tblButton" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td align="left">
<font id="Comp_Heading" class="Comp_Heading" face="arial"><< MD Notes >></font>
</td>
</tr>
<tr id="traDetail" class="traDetail">
<td>
<label onkeydown="return stopDataEntry()" id="lbl" oncut="" vbscript:window.event.returnvalue="false"
ondrop="" vbscript:window.event.returnvalue="false" ondblclick="lblDbl_Click('btn~~52437s80')"
contenteditable="false" onpaste="" vbscript:window.event.returnvalue="false"
ondrag="" vbscript:window.event.returnvalue="false">
<font id="Comp_Heading_Detail" class="Comp_Heading_Detail" face="arial"></font>
</label>
</td>
</tr>
</tbody>
</table>
vSoapText column also contains a html script in string, now i want to insert vsoaptext column value in the font tag Comp_Heading_Detail.
Our application was built in classic asp of which i don't know much either so i thought if i could do this with some handy script, it will make my life easy. Thanks a lot for your response.
You can use option with REPLACE string function
Let's assume you have two tables with this schemas
CREATE TABLE dbo.TreatmentOrders
(
Id int,
vSoapText nvarchar(100)
)
INSERT dbo.TreatmentOrders
VALUES(1, 'InsertedText1'),
(2, 'InsertedText2')
CREATE TABLE dbo.ClinicalDocuments
(
Id int,
TreatmentOrdersId int,
vReportText nvarchar(100)
)
INSERT dbo.ClinicalDocuments
VALUES(1, 1, '123 Treatment Order is 123'),
(2, 1, '12345 Treatment Order is 123'),
(3, 2, '123 Treatment Order is 123'),
(4, 2, '12345 Treatment Order is 123')
UPDATE d
SET d.vReportText =
REPLACE(vReportText,'Treatment Order is','Treatment Order is ' + o.vSoapText)
FROM dbo.ClinicalDocuments d
JOIN dbo.TreatmentOrders o ON d.TreatmentOrdersId = o.Id
Before
Id TreatmentOrdersId vReportText
1 1 123 Treatment Order is 123
2 1 12345 Treatment Order is 123
3 2 123 Treatment Order is 123
4 2 12345 Treatment Order is 123
After
Id TreatmentOrdersId vReportText
1 1 123 Treatment Order is InsertedText1 123
2 1 12345 Treatment Order is InsertedText1 123
3 2 123 Treatment Order is InsertedText2 123
4 2 12345 Treatment Order is InsertedText2 123
Demo on SQLFiddle
For update location of text "Comp_Heading_Detail" use this
UPDATE d
SET d.vReportText =
REPLACE(vReportText, 'font id="Comp_Heading_Detail"', 'font id="' + o.vSoapText+ '"')
FROM dbo.ClinicalDocuments d
JOIN dbo.TreatmentOrders o ON d.TreatmentOrdersId = o.Id

how to get the index value from the table?

I'm trying to get the index value for the column that I create index. How to do this? What I mean is something like below:-
index value indexed field data
______________ ____________________
0 apple
1 orange
2 manggo
Use $index.
More info: http://www.youtube.com/watch?v=jEpbjve5iHk
...
<tbody>
<tr ng-repeat="fruit in fruitBasket">
<td>{{$index}}</td> <!-- --------See this line! -->
<td>{{fruit}}</td>
</tr>
</tbody>
...