I'm looking for a way to check if text exists in a table cell.
I have no problem when there is only simple text in the cell, but my table cell has additional html tags and table.
I would like to check if the url exists (foo.bar.com) and then execute some logic or move to the next row.
Here is the one row snippet:
<tr bgcolor="#ffffff">
<td align="right" valign="top" nowrap="nowrap">99</td>
<td align="left" valign="top">
http://foo.bar.com<br>
<div style="margin-top: 8px">Show Details</div>
<div id="details_1" style="display: none;">
<table class="url-tracking-details">
<tbody>
<tr>
<td align="left" valign="top" nowrap="nowrap">Product:</td>
<td align="left" valign="top" nowrap="nowrap">- foo <br>- bar <br>- foobar</td>
</tr>
<tr>
<td align="left" valign="top" nowrap="nowrap">Version:</td>
<td align="left" valign="top" nowrap="nowrap">foo 4.2</td>
</tr>
<tr>
<td align="left" valign="top" nowrap="nowrap">Categorization:</td>
<td align="left" valign="top" nowrap="nowrap">- bar<br></td>
</tr>
</tbody>
</table>
</div>
</td>
<td align="center" valign="top" nowrap="nowrap">Closed</td>
<td align="center" valign="top" nowrap="nowrap">25/May/2022</td>
<td align="center" valign="top" nowrap="nowrap">25/May/2022</td>
</tr>
I've tried many things, including:
store | http://foo.bar.com | url
store text | xpath=//form/table/tbody/tr[2]/td[2] | cell
execute script | if (${cell}.startsWith(${url})) { return true; } else { return false }; | x
assert | x | true
but I'm getting 'Failed: Unexpected token in JSON at position 20'
So the full xpath for that url:
/html/body/div[2]/div[3]/div[2]/div[2]/div/div/div/div[2]/div1/div/div/form/table/tbody/tr[2]/td[2]/text()
How can I catch just this text?
I got it.
store | http://foo.bar.com | url
verify element present | xpath=//form/table/tbody/tr[2]/td[2][text()='${url}']
and here is an example with conditional logic:
the verify element present was changed to store xpath count and then assigned to the variable out (1 if true, 0 if false).
Related
I have created this table in my Qweb report and as you can see this table has borders. But how can I remove border for <tfoot element only? It should be bordered on <thead and <tbody.
Do I need to do it with custom CSS somehow?
<table style="border-color:grey;" class="table-bordered table-sm o_main_table" name="moves_table">
<thead>
<tr>
<th>No</th>
<th>Description</th>
<th class="text-center">Code</th>
<th class="text-right">Units</th>
<th class="text-right">Quantity</th>
<th class="text-right">Package quantity</th>
<th class="text-right">Net weight (kg)</th>
<th class="text-right">Weight incl. packaging</th>
<th class="text-right">Type of package</th>
</tr>
</thead>
<tbody class="invoice_tbody">
<tr t-foreach="o.move_ids_without_package" t-as="l">
<td class="text-center">
<span t-esc="l_index + 1" />
</td>
<td>
<span t-field="l.name"/>
</td>
<td>
<span t-field="l.product_id.default_code"/>
</td>
<td class="text-right">
<span t-field="l.product_uom.name"/>
</td>
<td class="text-right">
<span t-esc="'%.2f'%(l.product_uom_qty)"/>
</td>
<td class="text-right">
<span t-esc="'%.2f'%(l.product_uom_qty)"/>
</td>
<td class="text-right">
<span t-esc="'%.2f'%(l.product_uom_qty)"/>
</td>
<td class="text-right">
<span t-esc="'%.2f'%(l.product_uom_qty)"/>
</td>
<td class="text-right">
<span t-esc="'%.2f'%(l.product_uom_qty)"/>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td></td>
<td class="text-right"><span><strong>Total amount</strong></span></td>
<td class="text-right"><span t-esc="sum(o.move_ids_without_package.mapped('product_uom_qty'))"/></td>
<td class="text-right"><span t-esc="sum(o.move_ids_without_package.mapped('product_uom_qty'))"/></td>
<td class="text-right"><span t-esc="sum(o.move_ids_without_package.mapped('product_uom_qty'))"/></td>
<td class="text-right"><span t-esc="sum(o.move_ids_without_package.mapped('product_uom_qty'))"/></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="text-right"><span><strong>Total Weight</strong></span></td>
<td></td>
<td></td>
<td></td>
<td class="text-right"><span t-esc="sum(o.move_ids_without_package.mapped('product_uom_qty'))"/></td>
</tr>
</tfoot>
</table>
I suggest you do this the right way using css file, not style attributes because if you need this table, in another report you are going to repeat your self a lot and you are going to define style attribute in every td tag inside tfoo tag:
create and add css file to reports:
<template id="assets_common" name="Table no foot border" inherit_id="web.report_assets_common">
<xpath expr="." position="inside">
<link href="/your_folder_name/static/src/css/table_report_css.css" rel="stylesheet"/>
</xpath>
</template>
In your table_report_css.css file use a special class to distinct your table no-footer-border and gray-border to make border gray:
/* notice the table should have this two class */
.table-bordered.gray-border {
border-color:grey;
}
/* hide tr border inside tfoo I think this is not needed */
.table-bordered.no-footer-border tfoo tr{
border: border: none;
}
/* hide border td border inside tfoo tag this is required */
.table-bordered.no-footer-border tfoo td{
border: border: none;
}
Now in your template this two class to your table tag add table-bordered,gray-border and no-footer-border classes:
<!-- remove the style -->
<table class="table-bordered table-sm o_main_table gray-border no-footer-border" name="moves_table">
Note: don't forget to add the XML file that extends the report_assets_common to manifest, when you edit the css file no need to restart the server or upgrade your module. and this is for Odoo version >= 11.0, in < 11.0 the template of report assets is report.assets_common.
Please someone help me to write relative Xpath for below:
html/body/div[1]/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]/table[1]/tbody/tr[2]/td
As it do not contains any unique identifier firepath is giving an absolute Xpath but i want to use relative Xpath.
As the provided html code doesn't contains any class or id, thus you need to use below mentioned Xpath only:
html/body/div[1]/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/div/font/b
But if you add some class or id in your html like shown below:
<html><body><div><table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <tr> <tr valign="top"> <td height="101"> <table width="270" cellspacing="0" cellpadding="2" border="0"> <tbody> <tr bgcolor="#CCCCCC"> <td width="80%"> <td width="20%"> <div id="price" align="right"> <font face="Arial, Helvetica, sans-serif, Verdana" size="2"> <b>$398</b> </font> </div> </td> </tr> <tr> <tr bgcolor="#CCCCCC"> <tr> <tr bgcolor="#CCCCCC"> </tbody> </table> </td> </tr> </tbody> </table></div></body></html>
Then you can use below mentioned Xpath:
.//*[#id='price']/font/b
<td class="data-display-field" width="20%" valign="top">
<table class="printtotal" cellspacing="0" cellpadding="0" width="100%" ><tbody>
<tr class="list-row">
<td class="data-display-field" width="60%" style="font-weight: bold" align="center" colspan="2">Order Totals</td>
</tr>
<tr class="list-row">
<td class="data-display-field" width="60%" align="right" >Items total:</td>
<td class="data-display-field" width="40%" align="right" >
£323.36</td>
</tr>
<tr class="list-row">
<td class="data-display-field" width="60%" align="right" >Delivery total:</td>
<td class="data-display-field" width="40%" align="right" >
£7.00</td>
</tr>
<tr class="list-row">
<td class="data-display-field" style="color: #CC0000" width="60%" align="right" >Refund(s) total:</td>
<td class="data-display-field" style="color: #CC0000" width="40%" align="right" >(
£330.36)</td>
</tr>
How would I be able to make my web browser in VB select the money amount after "Refund(s) total:", I don't know how to do it as they all have the same class
you may use a unique id for elements like
<td id="id001"></td>
and with jquery you nay select id like this
$('#id001')
any reason that you are not using id?
Here is my HTML Script:
How to capture the link element in the tenth row?
HTML image
<table id="dataTableParticipantSearchResults" class="display" width="100%" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr align="left">
<th class="ui-state-default" width="20%" style="width: 154px;">
<div class="DataTables_sort_wrapper"></div>
</th>
<th class="ui-state-default" width="20%" style="width: 96px;"></th>
<th class="ui-state-default" width="15%" style="width: 69px;"></th>
<th class="ui-state-default" width="10%" style="width: 44px;"></th>
<th class="ui-state-default" width="20%" style="width: 156px;"></th>
<th class="ui-state-default" width="15%" style="width: 68px;"></th>
</tr>
</thead>
<tbody>
<tr class="odd" align="left">
<td></td>
</tr>
2.How to store that value, so that i can call the same value to access the link element?
You can always find these kinds of hyperlinks by first identifying the root table id- in this case it will be like this:
WebElement table = driver.findelement(by.id("dataTableParticipantSearchResults"));
Now you can use Xpath or Css Selector to select the link
try this:
table.findelement(by.cssSelector("a[href='LINK']")).click();
or try
table.findelement(by.linktext("LINK")).click();
or try
table.findelement(by.xpath(".//*[#id='dataTableParticipantSearchResults']/tbody/tr/td[0]")).click();
let me know if these work....cheers !
U can store the value in a WebElement and call any number of times.
WeElement link = table.findelement(by.xpath(".//*[#id='dataTableParticipantSearchResults']/tbody/tr/td[9]"));
now call it any number of times:
link.click();---------1st time
link.click();--------- 2nd time
and so on.....cheers !
I am attempting to pull a value and a header (string) from a website, but unable to find the element using selenium.
My Code
I used Firebug to get the XPath and this is what it determined:
//*[#id="DimensionForm"]/p[1]/table/tbody/tr[3]/td[3]
Code
Dim Right as double
Dim Marker as string
Marker = selenium.findElementByXPath("//*[#id="DimensionForm"]/p[1]/table/tbody/tr[2]/td[3]").getAttribute("value")
Right = selenium.findElementByXPath("//*[#id="DimensionForm"]/p[1]/table/tbody/tr[3]/td[3]").getAttribute("value")
HTML CODE
<form id="DimensionForm" name="validate" action="Dimension" method="post">
<div style="margin-top: 7px"></div>
<p><table width="100%" cellspacing="0" border="0" cellpadding="0" class="element">
<tr>
<td> </td><td class="formtitlenobg" colspan="6" align='right'>
AREA DIMENSIONS (AREA A) <span class='quote'> Front</span> 25.24</td>
</tr>
<tr align="right">
<td class="tablerowlightgreen" width=10> </td>
<th class="formtitle" width=250 align="left">Property</th>
<th class="formtitle" width=50>Check</th> <th class="formtitle" width=75>Front</th>
<th class="formtitle" width=75>Center</th><th class="formtitle" width=75>Left</th>
<th class="formtitle" width=120>Right</th>
<th class="formtitle" width=100>Total</th>
<td class="tablerow" width=50> </td>
<td class="tablerow"> </td>
</tr>
<tr align="right" nowrap>
<td> </td>
<td class="table" align="left"><strong>
Property O</strong></td>
<td class="table">+</td>
<td class="table">10</td>
<td class="table">12</td>
<td class="table"><strong>12</strong></td>
<td class="table"><strong><font class="front">
100</font></strong></td>
<td class="table">120</td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr></table>
You have incorrectly nested quotes:
selenium.findElementByXPath("//*[#id="DimensionForm"]/p[1]/table/tbody/tr[2]/td[3]")
Perhaps you meant:
selenium.findElementByXPath("//*[#id='DimensionForm']/p[1]/table//tr[2]/td[3]")
Note the single-quotes in the second line!