I have a html structure as below
<tr valign="middle" align="left">
<td> </td>
<td class="table_row"><div align="left"></div></td>
<td class="table_row"><div align="right" class="news_headline_txt"> </div></td>
<td class="table_row"><div align="right">28.02.2013</div></td>
<td class="table_row"><div align="right"><a onClick="window.open('show.php?id=id_9000')" href="javascript:;"></a></div></td>
<td> </td>
</tr>
I can get onclick value as below
"//a[contains(#onclick, 'id_')]/#href
but when i get the onclick value, i want match tr's third td values <td class="table_row"><div align="right">28.02.2013</div></td>contains 02.03
Thanks in advance
So you want to find a TR that has a td with a certain position, and then find the anchor within that:
//tr[td[position()=4][contains(text(), '02.03')]]//a[contains(#onclick, 'id_')]/#href
You could also use the sibling axis:
//td[position()=4][contains(text(), '02.03')]/following-sibling:td//a[contains(#onclick, 'id_')]/#href
Note the position check is for the 4th td, since there is a blank padding td at the beginning of the row.
Related
I am struggling to figure out how to access a button in a table cell. The HTML outline looks like this:
<tr role="row" class="odd">
<tr role="row" class="even">
<tr role="row" class="odd>
<tr role="row" class="even">
<td class="">6/27/2017</td>
<td>1234567</td>
<td>USG</td>
<td>Buy Settlement</td>
<td class="sorting_1">$1.00</td>
<td></td>
<td></td>
<td>
Reconcile
</td>
</tr>
<tr role="row" class="odd">
<tr role="row" class="even">
<tr role="row" class="odd">
<tr role="row" class="even">
Each tr has the same cell structure except for the information inside is different for every cell.
I am trying to access the link in the last td element however cannot seem to find any xpath that is valid because I do not have a unique parent cell. The '1234567' cell value is a unique identifier but I have not found how to use an XPath for a sibling node.
Can anyone help me?
This XPath,
//tr[td='1234567']/td/a[.='Reconcile']
will select the a element whose string value is Reconcile and which exists in a tr that contains a td with a string value of 1234567.
I see to possible solutions for this:
first:
//a[contains(#onclick, "bellLoadModal")]. This will have multiple results. Iterate them if you know what link-GUID you're lookin for.
second:
//tr[#role="row"]/td[1]. This will result in the nodes with the IDs. Iterate them checking for the ID you're lookin for and then go one node up from the current element and select the 7th child node. This is the one with the link.
I think the below XPath should work:
(//a[#class='btn btn-default btn-xs']) [last()]
If your requirement is for "the link in the last column of the row whose second column contains "1234567", then that's
//tr[td[2] = "1234567"]/td[last()]/a/#href
in a page there is some tags like this:
<tr class=" ev_modern">
<td align="left" valign="middle" title="1">1</td>
<td align="left" valign="middle" title="09:00:08" class="">09:00:08</td>
<td align="left" valign="middle">3000</td>
<td align="left" valign="middle" title="2539.00">2539.00</td>
</tr>
I looking for(row number, time, number1, number2) each of them, and tried many ways but I couldn't, one of them:
var elements = driver.FindElements(By.CssSelector("[class=' ev_modern']"));
elements is empty
how get information by selenium using C#?
Use following css selector to get to the td elements:
By.CssSelector("[class=' ev_modern'] td")
Then you can iterate through the list of elements.
Or if you want to get text from first row, do following:
driver.FindElement(By.CssSelector("[class=' ev_modern'] td:nth-child(1)")).Text;
Hope this helps.
I have html page with this code
<table class="data">
<tr>
<td class="head" >Time</td>
<td class="head right" >Pref</td>
<td class="head" >Name</td>
<td class="head">Descr</td>
</tr>
<tr>
<td colspan="4" class="date">
2014.03.17
</td>
</tr>
<tr valign="top" class="dat">
<td>22:02</td>
<td class="right">
3/2014
</td>
<td>
<a href="/reports/id=34">
<b>Company Name</b>
</a>
</td>
<td>
<a href=/reports/view/id=34" target="_blank" class="th">
Description
</a>
</td>
</tr>
<tr valign="top" class="date">
<td>21:16</td>
<td class="right">
8/2014
</td>
<td>
<a href="/reports/id=324">
<b>Company Name2</b>
</a>
</td>
<td>
<a href="reports/view/=324" target="_blank" class="th">
Description
</a>
</td>
</tr>
................................
</table>
Can you help me create regexp to extract data from table. I need this data 21:16,8/2014,Company Name2,Description
Thanks.
Do NOT try parsing HTML with Regex. You might get fairly far, but it's very easy to screw it up and it doesn't work well. It learned this the hard way once. Like others have mentioned in the comments. See:
https://stackoverflow.com/a/1732454/794380
You should try the Html Agility pack: http://htmlagilitypack.codeplex.com
Take a look here https://stackoverflow.com/a/19871589/307976
I use visual studio 2010 with framework2.0
I design a page use c# ,now ,just called A.aspx.
the page have a table to layout,
like
<table> <tr>
<td>
Name
</td>
<td>
<asp:TextBox .../>
<div id="div1" style="vertical-align: bottom;">
<img.. />
</div>
<div><img ../></div>
<asp:Label .../>
<asp:Label .../>
</td>
</tr>
</table>
Now ,I want to let second<td></td> layout one row. how to set up?
I try <td style ="float:left"> but not worked,it always show two row.
can somebody help me with this?
First understand your layout, here is an example with borders
If you want to float elements try a layout using div and css
A layout with tables is very hard to work with and nobody is doing it anymore. You can use tables for specific situation only if you like but most of the time try to use div layout and the other elements to organize content.
HTML
<table class="borde">
<tr class="borde">
<td class="borde">
Name
</td>
<td class="borde">
fffff
<div class="divRojo"></div>
fffff
</td>
</tr>
</table>
CSS
.borde { border:1px solid black; }
.divRojo { border:1px solid red; }
With one more row and the div
<table class="borde">
<tr class="borde">
<td class="borde">
Name
</td>
<td class="borde">
fffff
<div class="divRojo"></div>
fffff
</td>
</tr>
<tr>
<td colspan="2">
<div>Content in one column in a new row</div>
</td>
</tr>
</table>
You want your second <td> in one row? So, create another <tr>?
<table>
<tbody>
<tr>
<td>
Name
</td>
</tr>
<tr>
<td>
<textarea></textarea>
</td>
</tr>
</tbody>
</table>
http://jsbin.com/uJenUVOx/1/edit
I have fix this question ,the second <td> use <table> then can solve that question.
I'm trying to use a simple table nested in a cell to show a graph on my elections result page.
<td>
<%: result.candidateName %>
<table style="border:0; padding:2px;">
<tr>
<td style="width:50px; border:0; height:15px; color:Blue; padding:0; font-size:75%;"><%: result.percentWon %>%</td>
<td style="background-color:Blue; width:400px; border:0; height:15px;"></td>
</tr>
</table>
</td>
What I need to do is change the width figure in the cell style (set to 400px now) to be 4*result.percentWon, but I cant figure out how to put Aligator tags in the middle of the style string.
Yes I'm a noob (o: Can anyone school me?
You can put <%: ... %> where-ever you want:
<td style="background-color:Blue; width:<%:4*result.percentWon%>px; border:0; height:15px;"></td>