selenium not finding correct link using xpath - selenium

I'm trying to delete click on link generated by a previous test (a delete link) but I'm having great difficulty with xpath
Here is the error I am receiving
Invalid response while accessing the Selenium Server at 'http://localhost:4444/s
elenium-server/driver/': ERROR: Element xpath=(//td[normalize-space() ='Test tit
le 2']/following-sibling::td[3]/descendant::a[.='delete']) not found
here is my test
public function testdeleteStationTestCase()
{
$this->open("/upd8r_new/");
$this->click("css=a > img");
$this->waitForPageToLoad("30000");
$this->type("name=username", "glass2");
$this->type("name=password", "glass2");
$this->click("name=submit");
sleep(1);
$this->click("xpath=(//td[normalize-space() ='Test title 2']/following-sibling::td[3]/a[.='delete'])");
//$this->click("xpath=(//td[normalize-space() ='Test title 2']/following-sibling::td[3]/descendant::a[.='delete'][1])");
sleep(1);
$this->assertTrue($this->isTextPresent("Station deleted!"),"Station Deleted");
}
as you can see my commented out line i have been trying all sorts of combinations to get the test to run-
here is the html page I am testing against- i have added a line of text where I am trying to click
<body>
<!-- social media header -->
<div class="main">
<div class="header">
Central Control Panel
</div>
<div class="logo">
<img src="http://localhost/upd8r_new/imgs/loyalty_connect2.png"/>
</div>
<div style="clear:both"></div>
<ul class="Menu" id="maintab">
<li class="selected" rel="home">HOME </li>
<li rel="retail">
RETAIL </li>
<li rel="stats"> STATS</li>
<li
rel="social_media_settings"> SETTINGS</li>
<li rel="logout">LOGOUT </li>
</ul>
<div style="clear:both"></div>
<div style="text-align:left;width:980px;height:40px;background-color:#0E477A;margin:auto;padding-top:0px;">
<div style="width:700px;text-align:left;padding-left:10px;float:left">
<div id="logout" class="submenustyle">
</div>
<div id="retail" class="submenustyle">
<ul class="sub_menu">
<li>USERS</li>
<li>COMPETITIONS</li>
</ul>
</div>
<div id="home" class="submenustyle">
<ul class="sub_menu">
<li>ADD LIKESTATION</li>
<li>ADD PICSTATION</li>
<li>ADD VIDSTATION</li>
</ul>
</div>
<div id="socialmedia_users" class="submenustyle">
</div>
<div id="stats" class="submenustyle">
<ul class="sub_menu">
<li>STATS HOME</li>
<li>FACEBOOK STATS</li>
</ul>
</div>
<div id="social_media_settings" class="submenustyle">
<ul class="sub_menu">
<li>SETTINGS HOME</li>
<li>NETWORKS TO USE</li>
<li>PRE REGISTRATION</li>
<li>
APP SETTINGS
</li>
</ul>
</div>
</div>
<div style="float:right;font-weight:bold;color:#fff;margin-top:12px;margin-right: 20px;">
Logged In As: glass2 </div>
</div>
<div style="clear:both"></div>
<div style="padding-top:30px;padding-left:10px">Station deleted! </div>
<div style="padding-left:10px">
<table width="700px" align="left" style="text-align:left;">
<tr>
<td style="font-weight:bold">Pre-Registration</td>
<td>http://localhost/upd8r_new/retail/register/80</td>
</tr>
</table>
<div style="clear:both"></div>
<table width="800px" align="left" style="text-align:left;">
<tr style="font-weight:bold;background-color:#f1f1f1">
<td colspan="6" STYLE="text-align:center;font-weight:bold">LIKESTATIONS</td>
</tr>
<tr style="font-weight:bold;background-color:#f1f1f1">
<td width="10%">STATION ID</td>
<td width="32%">STATION NAME</td>
<td width="25%">LINK TITLE</td>
<td width="10%">STATION STATS</td>
<td width="15%">LAST POST</td>
<td width="8%"></td>
</tr>
<tr>
<td>gla20311344 </td>
<td>http://localhost/upd8r_new/socialmedia/edit/gla20311344 </td>
<td>Webcast </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla2084629867 </td>
<td>http://localhost/upd8r_new/socialmedia/edit/gla2084629867 </td>
<td>tes this link title3 </td>
<td>STATS </td>
<td>4 weeks ago</td>
<td>delete</td>
</tr>
</table>
<div style="clear:both"></div>
<table width="620px" align="left" style="text-align:left;">
<tr style="font-weight:bold;background-color:#f1f1f1">
<td colspan="5" STYLE="text-align:center;font-weight:bold">FACEBOOK PIC STATIONS</td>
</tr>
<tr style="font-weight:bold;background-color:#f1f1f1">
<td width="15%">STATION ID</td>
<td width="50%">STATION TITLE</td>
<td width="10%">STATION STATS</td>
<td width="15%">LAST POST</td>
<td width="10%"></td>
</tr>
<tr>
<td>gla1079978359 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>**link I'm trying to click**delete</td>
</tr>
<tr>
<td>gla1229158969 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla1256364596 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla1529784490 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla159062284 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla175038477 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla1777127061 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla180142977 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla1950664292 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla1971709701 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla2028774169 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla2035285297 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla2072665757 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla2115042517 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla2141659529 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla4705592 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla565900575 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla608150382 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
<tr>
<td>gla979271929 </td>
<td>Test title 2 </td>
<td>STATS </td>
<td>0</td>
<td>delete</td>
</tr>
</table>
<div style="clear:both"></div>
<table width="520px" align="left" style="text-align:left;">
<tr style="font-weight:bold;background-color:#f1f1f1">
<td colspan="4" STYLE="text-align:center;font-weight:bold">FACEBOOK VIDEO STATIONS</td>
</tr>
<tr style="font-weight:bold;background-color:#f1f1f1">
<td width="20%">STATION ID</td>
<td width="60%">STATION TITLE</td>
<td width="60%">STATION STATS</td>
<td width="20%"></td>
</tr>
</table>
<div style="clear:both"></div>
</div>
</div>
<div class="footer">
<div style="float:left;padding-top:20px;padding-left:20px;font-size:10px;font-family:arial"></div>
<div style="padding-top:20px;float:right;padding-right:30px;"><img src="http://localhost/upd8r_new/imgs/excelerated.jpg"/></div>
</div>
</body>
</html>

Your problem is in sleep(1);
In this place instead of sleep(1); you should use this:
$this->waitForCondition("selenium.isElementPresent(\'css=table:contains(\'FACEBOOK PIC STATIONS\') a:contains(\'delete\')\')", "20000");
And by the way, while you use selenium RC you can reach your delete link with this css (with webdriver it will not work as :contains is not a part of css spec):
$this->click("css=table:contains('FACEBOOK PIC STATIONS') a:contains('delete')");
Also replace all sleep(1); with appropriate waitForCondition commands

Install "XPath Checker 4.4" add-ons in Firefox. So for that object you will get proper xpath using this add-ons..
So,
click xpath=xpath for that object

Related

xpath method of Selenium does not work for Google chrome

I don't have a lot of experience with Selenium but I am trying to run a code which search for an element in HTML with chromedriver. I keep getting an error as below. The first thing I would like to confirm is that this error cannot be due to the connection with Chromedriver to the web but is because of the way the python script search in the HTML code. Any help would be appreciated.
The error:
('no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(text(),\'Find exited companies announced\')]/../.."}\n (Session info: headless chrome=91.0.4472.101)', None, None)
The code source:
<div id="logon-brownContent" style="width:100%;display:true;;padding-bottom: 0px;" class="hideforprinting">
<table width="" cellpadding="0" cellspacing="0" class="">
</table>
</div>
</div>
</td></tr></table>
</div>
</td>
<td class="homepage_mainbody-headlines">
<table class="framework_standard">
<tr>
<td colspan="2" valign="top">
<form action="exitbroker.asp?" method="post" name="oz" id="oz" sumbit="javascript:return validate();">
<input type="hidden" name="verb" value="8" />
<input type="hidden" name="dateformat" value="dd/mm/yyyy" />
<input type="hidden" name="contextid" value="1032390856" />
<input type="hidden" name="statecodelength" value="0" />
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<table>
<tr>
<td class="framework_page-title">
<span class="framework_page-title">PE Exit Companies: Search</span><br/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="1"><img src="/images/spacer.gif" height="13" width="1"></td>
</tr>
</table>
<table class="criteriaborder" cellspacing="0" cellpadding="2" width="100%" border="0">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="0" border="0" style="width:100%;">
<tbody>
<tr>
<td valign="top">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td align="center" valign="middle" width="100%" height="18" class="criteriaheader2">Exits</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br />Exit Types</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="top"><td width="200"><input type="checkbox" name="exitdealtype" value="ipo"/>Initial Public Offering</td><td width="200"><input type="checkbox" name="exitdealtype" value="sbo"/>Secondary Buyout</td><td width="200"><input type="checkbox" name="exitdealtype" value="tradesale"/>Trade Sale</td></tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br />Date Range</td>
</tr>
<tr>
<td>
Find exited companies announced<br><br>
</td>
</tr>
<tr>
<td>
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td>From </td>
<td><input type="text" name="datefrom" style="width:100" value=""></td>
<td> To </td>
<td><input type="text" name="dateto" style="width:100" value=""></td>
<td> Clear Date</td>
</tr>
<tr>
<td> </td>
<td><span class="hint">(dd/mm/yyyy)</span></td>
<td> </td>
<td><span class="hint">(dd/mm/yyyy)</span></td>
<td> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<br />
Please Note: The default start date for our searches has been changed to 01/01/2005. You can still access all
<br />
of our historical data by inserting the desired start date above. For help or further information please contact
<br />
your Customer Relationship Consultant.
<br />
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br />Industry</td>
</tr>
<tr>
<td>
Find exited companies in these sectors.
<br />The industries defined here are affiliated with both the core business and divisions of the portfolio/exited companies.
<br />Multiple select using ctrl and click. The default is set to all.<br><br>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><span class="criterialabel">Sectors<img src="/includes/images/mm-info-icon.gif"></span></td>
<td><span class="criterialabel">Sub-Sectors</span></td>
</tr>
<tr>
<td><select multiple="multiple" size="6" name="sectorcode" style="width:250px" onChange="javascript:emptyListBox(document.oz.subsectorcode);fillSelect(document.oz.subsectorcode,null,buildSelectedItems(document.oz.sectorcode));"></select> </td>
<td><select multiple="multiple" size="6" name="subsectorcode" style="width:250px"></select> </td>
</tr>
<tr>
<td><a name="selectAllSubsectorLink" href="javascript:fillSelect(document.oz.subsectorcode,null,buildSelectedItems(document.oz.sectorcode));selectAll(document.oz.sectorcode);fillSelect(document.oz.subsectorcode,null,buildSelectedItems(document.oz.sectorcode));">Select All Sectors</a> </td>
<td>Select All Sub-Sectors </td>
</tr>
<tr>
<td>Clear All<br><br></td>
</tr>
<tr>
<td colspan="4">
<input type="hidden" name="normalsectorsearch" value="" />
<input type="hidden" name="normalsubsectorsearch" value="" />
<input type="checkbox" name="domsectoronly" value="true" onclick="javascript:deselectAll(document.oz.subsectorcode);setItemDisableStatus(document.oz.subsectorcode);setItemDisableStatus(document.oz.selectAllSubsectorLink);">Search by dominant sector only<a href="javascript:displayPEPortfolioDominantSectorCountryGlossary('../includes/glossary');"><img src="/includes/images/mm-info-icon.gif" title="More information" />
</td>
</tr>
</table>
</td>
<!--
<td><select size="6" multiple="multiple" name="sectorcode" style="width:250px" ></select> </td>
</tr>
<tr>
<td>
Select All
Clear All
</td>
</tr>
-->
</tr>
<tr>
<td style="TEXT-ALIGN: right;" class="search_buttons_right">
<input type="button" value="Save Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=1;document.oz.target='_self';document.oz.submit();};"/>
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=28;defaultDatesWithLocale( document.oz.datefrom, document.oz.dateto, 'dd/mm/yyyy' );if (verifyDateSubSectors(document.oz.datefrom.value)) {countWindow();document.oz.target='_self';document.oz.submit();}}"><img src="/images/button_countresults.gif" border="0" /></a -->
<input type="button" value="Count Results" class="framework_flatbutton" onclick="javascript:submitCount();" />
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=8;defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );document.oz.target='_self';if (verifyDateSubSectors(document.oz.datefrom.value)) {document.oz.target='_self';document.oz.submit();}};"><img src="/images/button_search.gif" border="0" /></a -->
<input type="button" value="Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {
document.oz.verb.value=8
;document.oz.target='_self'
defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );
; document.oz.target='_self';
document.oz.submit();
}" />
</td>
</tr>
</tbody>
</table>
</tr>
</td>
</tbody>
</table>
<table>
<tr>
<td>
<br>
</td>
</tr>
</table>
<table class="criteriaborder" cellspacing="0" cellpadding="2" width="100%" border="0">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="0" border="0" style="width:100%;">
<tbody>
<tr>
<td valign="top">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td align="center" valign="middle" width="100%" height="18" class="criteriaheader2">Further Search Criteria</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>Geography</td>
</tr>
<tr>
<td>Find exited companies in these locations.
<br />Multiple select using ctrl and click. The default is set to all. </td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><img src="/images/spacer.gif" width="10" height="1" alt="" /></td><td> </td>
</tr>
<tr>
<td><select multiple="multiple" size="6" name="areacode" style="width:200px" onChange="javascript:emptyListBox(document.oz.regioncode);emptyListBox(document.oz.countrycode);fillSelect(document.oz.regioncode,null,buildSelectedItems(document.oz.areacode));emptyListBox(document.oz.statecode);"></select></td>
<td><select multiple="multiple" size="6" name="regioncode" style="width:200px" onChange="javascript:emptyListBox(document.oz.countrycode);fillSelect(document.oz.countrycode,null,buildSelectedItems(document.oz.regioncode));emptyListBox(document.oz.statecode);"></select></td>
<td><select multiple="multiple" size="6" name="countrycode" style="width:200px" onChange="javascript:emptyListBox(document.oz.statecode);fillSelect(document.oz.statecode,null,buildSelectedItems(document.oz.countrycode));"></select></td>
<td> </td><td><select multiple="multiple" size="6" name="statecode" style="width:200px"></select></td>
</tr>
<tr>
<td>Select All</td>
<td>Select All</td>
<td>Select All</td>
<td> </td><td>Select All</td>
</tr>
<tr>
<td>Clear All</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>PE House</td>
</tr>
<tr>
<td>Find exit companies who are currently held by specific PE Houses.
<br />Maximum of 50 selections allowed.</td >
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a class="search_lookup" href="javascript:openWin('qpehousenotapproved','hyperlink','pehousesysid','select-multiple','pehousesysiddescription','');">Lookup</a>
</td>
</tr>
<tr>
<td>
<select size="4" multiple="multiple" name="pehousesysid" style="width:350px"></select>
<input type="hidden" name="pehousesysiddescription" />
</td>
</tr>
<tr>
<td>
Remove
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>Advisors</td>
</tr>
<tr>
<td>
Find exited companies who have been advised by these companies.
<br />Maximum of 50 selections allowed.
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a class="search_lookup" href="javascript:openWin('ecadvisor','hyperlink','advisorcompanysysid','select-multiple','advisorcompanysysiddescription','');">Lookup</a>
</td>
</tr>
<tr>
<td>
<select size="4" multiple="multiple" name="advisorcompanysysid" style="width:350px"></select>
<input type="hidden" name="advisorcompanysysiddescription" />
</td>
</tr>
<tr>
<td>
Remove
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><br /><span class="criteriasectionheader">Deal Value</span></td>
</tr>
<tr>
<td>Find exited companies with the following deal value. </td>
</tr>
<tr>
<td>
<table>
<tr>
<td><p><span class="criterialabel">Currency</span></p></td>
<td> </td>
<td><select id="currencycode" name="currencycode"><option value="AUD">AUD</option>
<option value="CHF">CHF</option>
<option value="CNY">CNY</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="HKD">HKD</option>
<option value="INR">INR</option>
<option value="JPY">JPY</option>
<option value="USD" selected="">USD</option></select></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="180"><p><span class="criterialabel">Minimum value in millions</span></p></td>
<td> </td>
<td><p><input type="text" name="mindealvalue" size="12" value="" onkeypress="checkMinimumValue();" onkeyup="checkMinimumValue();" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="180"><span class="criterialabel">Maximum value in millions</span></td>
<td> </td>
<td><input type="text" name="maxdealvalue" size="12" value=""></td>
</tr>
</table>
</td>
</tr>
<tr><td><br>Include deals with undisclosed value <input type="checkbox" name="undiscloseddealvalues" value="true" Checked></td></tr>
<tr>
<td class="criteriasectionheader"><br/>Exited Companies</td>
</tr>
<tr>
<td>Maximum of 50 selections allowed.</td >
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a class="search_lookup" href="javascript:openWin('eccompany','hyperlink','eccompanysysid','select-multiple','eccompanysysiddescription','');">Lookup</a>
</td>
</tr>
<tr>
<td>
<select size="4" multiple="multiple" name="eccompanysysid" style="width:350px"></select>
<input type="hidden" name="eccompanysysiddescription" />
</td>
</tr>
<tr>
<td>
Remove
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>Free Text Search</td>
</tr>
<tr>
<td>Please use the Free Text Search by typing in a keyword or phrase to identify the required portfolio.
<br />
<span class="hint">Searches on companies' information, deal description, and condition, type, nature, consideration structure.<br><br></span>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" class="criterialabel">Search</td>
<td><input type="text" name="textsearch" style="width:250px" value="" /></td>
<td><table border="0" cellpadding="0" cellspacing="0">
<tr valign="top"><td width="350"><input checked type="radio" name="andorfreetext" value="and"/>Match all words<br><input type="radio" name="andorfreetext" value="or"/>Match any word<br><input type="radio" name="andorfreetext" value="phrase"/>Match exact phrase</td></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="TEXT-ALIGN: right;" class="search_buttons_right">
<input type="button" value="Save Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=1;document.oz.target='_self';document.oz.submit();};"/>
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=28;defaultDatesWithLocale( document.oz.datefrom, document.oz.dateto, 'dd/mm/yyyy' );if (verifyDateSubSectors(document.oz.datefrom.value)) {countWindow();document.oz.target='_self';document.oz.submit();}}"><img src="/images/button_countresults.gif" border="0" /></a -->
<input type="button" value="Count Results" class="framework_flatbutton" onclick="javascript:submitCount();" />
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=8;defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );document.oz.target='_self';if (verifyDateSubSectors(document.oz.datefrom.value)) {document.oz.target='_self';document.oz.submit();}};"><img src="/images/button_search.gif" border="0" /></a -->
<input type="button" value="Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {
document.oz.verb.value=8
;document.oz.target='_self';
defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );
document.oz.target='_self';
document.oz.submit();
}" />
</td>
</tr>
</tbody>
</table>
</tr>
</td>
</tbody>
</table>
</form>
<script LANGUAGE="JavaScript">
<!--
function validatePage(objitem) {
selectAll(objitem.pehousesysid);
selectAll(objitem.eccompanysysid);
objitem.eccompanysysid.required=false;
objitem.eccompanysysid.description='Portfolio Company Name';
objitem.eccompanysysid.datatype='alphanumeric';
selectAll(objitem.advisorcompanysysid);
objitem.advisorcompanysysid.required=false;
objitem.advisorcompanysysid.description='Advisor Name';
objitem.advisorcompanysysid.datatype='alphanumeric';
// locale info.
objitem.localedateformat='dd/mm/yyyy';
objitem.localecurrencycode='USD';
objitem.localelanguagecode='en_eu';
objitem.localetimezone='235';
objitem.mindealvalue.required=false;
objitem.mindealvalue.description='Currency minimum value in millions';
objitem.mindealvalue.datatype='decimal';
objitem.mindealvalue.min =0;
objitem.mindealvalue.max=1000000000000000000;
objitem.maxdealvalue.required=false;
objitem.maxdealvalue.description='Currency maximum value in millions';
objitem.maxdealvalue.datatype='decimal';
objitem.maxdealvalue.min=0;
objitem.maxdealvalue.max=1000000000000000000;
objitem.datefrom.required=false;
objitem.datefrom.description='Date from';
objitem.datefrom.datatype='date';
objitem.dateto.required=false;
objitem.dateto.description='Date to';
objitem.dateto.datatype='date';
if (objitem.statecode)
{
objitem.statecodelength.value = objitem.statecode.length;
}
// DanielC: 7/11/08: Case 107136: set the hidden field so that it will end up in the token XML and can be used in criteria.xml
if (document.oz.domsectoronly.checked == false)
{
document.oz.normalsectorsearch.value = "true";
document.oz.normalsubsectorsearch.value = "true";
}
return verify(objitem,false);
}
function submitCount()
{
if (validatePage(document.oz)) {
var dOz = document.oz;
//need to change pPopup variable to pPopup=1 to ensure no chrome on popup in event of failure
var vAction = dOz.action;
dOz.action = (dOz.action.search(/pPopup/) == -1) ? dOz.action+= "&pPopup=1" : dOz.action.replace(/pPopup=./,"pPopup=1");
defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );
dOz.verb.value=28;
countWindow();
document.oz.submit();
dOz.action = vAction;
}
}
//-->
</script>
</td>
</tr>
</table>
</td>
<td class="homepage_mainbody-leaguetbl"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%"><img src="/images/spacer.gif" width="1" height="1"></td>
</tr>
</table>
</td>
</tr>
</table>
</div><footer class="acuris-footer" xmlns:msxsl="urn:schemas
A piece of code with xpath not sending error:
def openSearchPageCommon(self,url,clear_xpath) :
self.drv.get(url)
for x in self.drv.find_elements_by_xpath(clear_xpath) :
x.click()
def openSearchPage(self) :
xpath = "//form[#action='portfoliobroker.asp?']//table//*[contains(text(),'Clear Date')]"
self.openSearchPageCommon(self.tgt,xpath)
Full error:
Traceback (most recent call last):
File "mmmm_lib.py", line 73, in __init__
self.drv.find_element_by_xpath("//*[contains(text(),'Find exited companies announced')]/../..")
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(text(),'Find exited companies announced')]/../.."}
May be its because the element you are trying to locate is in an iframe or in a shadow dom. And also make sure that the xpath points only one element in the Dom.
If its in an iframe you need switch to that frame and then try to locate the element.
if its in a shadow root, open you need to get the shadow-root first to locate the required element.
I think we should try with css selector written below :-
table.criteriaborder:nth-of-type(2) tr:nth-of-type(5) td
since the xpath that you are using, depends on a text which is basically a text node
if it's python that you are working on, you could try the below code :
print(driver.find_element_by_css_selector("table.criteriaborder:nth-of-type(2) tr:nth-of-type(5) td").text)

Stripping HTML elements

I am trying to migrate a webforum where I don't have control over database etc and uses Scrapy to pick the pieces. It is based on an old phpBB forum 2.x.
It is not very well structured so a few challenges.
I now have a HTML string where I need to remove surrounding <td></td>, <span></span>and the Report link at bottom
Starting with:
<td colspan="2"><span class="postbody"></span>
<table width="90%" cellspacing="1" cellpadding="3" border="0" align="center">
<tr>
<td><span class="genmed"><b>Some wrote :</b></span></td>
</tr>
<tr>
<td class="quote">
<table width="90%" cellspacing="1" cellpadding="3" border="0" align="center">
<tr>
<td><span class="genmed"><b>Another wrote:</b></span></td>
</tr>
<tr>
<td class="quote">Just for test
a link
</td>
</tr>
</table>
<span class="postbody">
<br>
<br>
Test quote #1</span>
</td>
</tr>
</table>
<span class="postbody">
<br>
<br>
Test quote #2<br>
Another link: linktext<br>
_________________<br>/ author
<br>
text<br>
<div align="right">[ Rapportera
] </div>
</span><span class="gensmall"></span>
</td>
Wanted result:
<table width="90%" cellspacing="1" cellpadding="3" border="0" align="center">
<tr>
<td><span class="genmed"><b>Some wrote :</b></span></td>
</tr>
<tr>
<td class="quote">
<table width="90%" cellspacing="1" cellpadding="3" border="0" align="center">
<tr>
<td><span class="genmed"><b>Another wrote:</b></span></td>
</tr>
<tr>
<td class="quote">Just for test
a link
</td>
</tr>
</table>
<span class="postbody">
<br>
<br>
Test quote #1</span>
</td>
</tr>
</table>
<br>
<br>
Test quote #2<br>
Another link: linktext<br>
_________________<br>/ author
<br>
text<br>
Any tips?
Why not simply do
html = html.strip('<td colspan="2"><span class="postbody"></span>')
and
html = html.strip('</td>').strip().strip('</span>')

Empty rows with datatables / Bootstrap table

I don't understand the behavior of my bootstrap 3.3.7 + datatables 1.10.15 table.
Here is my initial HTML Table :
<table id="types-2" class="table-bordered table-striped table-condensed">
<thead>
<tr>
<th class="both" data-field="Type" data-sortable="true">Type</th>
<th class="both" data-field="Name" data-sortable="true">City</th>
<th class="both" data-field="City" data-sortable="true">‰ city</th>
<th class="both" data-field="Department" data-sortable="true">‰ department </th>
<th class="both" data-field="Region" data-sortable="true">‰ region</th>
</tr>
</thead>
<tbody>
<tr>
<td>Case 1</td>
<td>782 </td>
<td>13.84‰ </td>
<td>18.38‰ </td>
<td>24.25‰ </td>
</tr>
<tr>
<td>Case 2</td>
<td>267 </td>
<td>4.73‰ </td>
<td>5.37‰ </td>
<td>7.87‰ </td>
</tr>
<tr>
<td>Case 3 </td>
<td>191 </td>
<td>3.38‰ </td>
<td>4.27‰ </td>
<td>4.02‰ </td>
</tr>
<tr>
<td>Case 4</td>
<td>144 </td>
<td>0.04‰ </td>
<td>0.29‰ </td>
<td>0.24‰ </td>
</tr>
</tbody>
</table>
I'm using this script in order to hide pagination and search, to order by colomn 1 desc value, and to be responsive and to display directly all the rows.
<script>
jQuery(document).ready(function() {
jQuery('#types-2').DataTable( {
"bPaginate": false,
"bInfo" : false,
"responsive": true,
"searching": false,
"aaSorting": [[1,'desc']],
responsive: {
details: {
display: jQuery.fn.dataTable.Responsive.display.childRowImmediate,
type: ''
}
}
} );
} );
</script>
What I can't figure is why the script is adding two empty div class rows at the begining and the end of the table :
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>
[...]
<div class="row">
<div class="col-sm-5"></div>
<div class="col-sm-7"></div>
</div>
The full render is :
<div id="types-2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>
<div class="row">
<div class="col-sm-12">
<table id="types-2" class="table-bordered table-striped table-condensed dataTable no-footer dtr-" role="grid" style="width: 605px;">
<thead>
<tr role="row">
<th class="both sorting" data-sortable="true" data-field="Type" tabindex="0" aria-controls="types-2" rowspan="1" colspan="1" style="width: 114px;" aria-label="Délit: activate to sort column ascending">Délit</th>
<th class="both sorting_desc" data-sortable="true" data-field="Name" tabindex="0" aria-controls="types-2" rowspan="1" colspan="1" style="width: 127px;" aria-sort="descending" aria-label="Abrets en Dauphiné : activate to sort column ascending">Abrets en Dauphiné
</th>
<th class="both sorting" data-sortable="true" data-field="City" tabindex="0" aria-controls="types-2" rowspan="1" colspan="1" style="width: 140px;" aria-label="‰ Abrets en Dauphiné: activate to sort column ascending">‰ Abrets en Dauphiné
</th>
<th class="both sorting" data-sortable="true" data-field="Department" tabindex="0" aria-controls="types-2" rowspan="1" colspan="1" style="width: 48px;" aria-label="‰ Isère : activate to sort column ascending">‰ Isère
</th>
<th class="both sorting" data-sortable="true" data-field="Region" tabindex="0" aria-controls="types-2" rowspan="1" colspan="1" style="width: 101px;" aria-label="‰ Rhône-Alpes: activate to sort column ascending">‰ Rhône-Alpes
</th>
</tr>
</thead>
<tbody>
<tr class="odd" role="row">
<td tabindex="0">Case 1</td>
<td class="sorting_1">782 </td>
<td>13.84‰ </td>
<td>18.38‰ </td>
<td>24.25‰ </td>
</tr>
<tr class="even" role="row">
<td tabindex="0">Case 2</td>
<td class="sorting_1">267 </td>
<td>4.73‰ </td>
<td>5.37‰ </td>
<td>7.87‰ </td>
</tr>
<tr class="odd" role="row">
<td tabindex="0">Case 3</td>
<td class="sorting_1">191 </td>
<td>3.38‰ </td>
<td>4.27‰ </td>
<td>4.02‰ </td>
</tr>
<tr class="even" role="row">
<td tabindex="0">Case 4 </td>
<td class="sorting_1">144 </td>
<td>0.04‰ </td>
<td>0.29‰ </td>
<td>0.24‰ </td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-sm-5"></div>
<div class="col-sm-7"></div>
</div>
</div>
I can't figure where these additional 2 div class rows come from. Do you have any clue and how can I prevent them to appear (except display:none them)
Thanks.
It is added by default value for dom option when using Bootstrap styling.
If you're not using search, pagination and info controls, you can override the default layout with the following option.
dom: 'rt'
See official documentation for more information.

Print all lines from account.invoice.line model

I created a new template for printing, and i want to customize it so it prints all the lines from account.invoice.line model. Is there a way you can do that. Here is the code of the template so far.
<t t-name="account.specifikacioni_report_document">
<t t-call="report.external_layout">
<div class="page">
<table class="table table-condensed">
<thead>
<tr>
<th>Description</th>
<th>Quantity</th>
<th class="text-right">Unit Price</th>
<th class="text-right" groups="sale.group_discount_per_so_line">Discount (%)</th>
<th class="text-right">Taxes</th>
<th class="text-right">Amount</th>
</tr>
</thead>
<tbody class="invoice_tbody">
<tr t-foreach="o.invoice_line" t-as="l">
<td>
<span t-field="l.name"/>
</td>
<td>
<span t-field="l.quantity"/>
<span t-field="l.uos_id" groups="product.group_uom"/>
</td>
<td class="text-right">
<span t-field="l.price_unit"/>
</td>
<td class="text-right" groups="sale.group_discount_per_so_line">
<span t-field="l.discount"/>
</td>
<td class="text-right">
<span t-esc="', '.join(map(lambda x: x.name, l.invoice_line_tax_id))"/>
</td>
<td class="text-right">
<span t-field="l.price_subtotal" t-field-options="{"widget": "monetary", "display_currency": "o.currency_id"}"/>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
This prints invoice lines for one invoice cause I copied the account.report_invoice_document and just edited it, but how can I list all invoice lines here not only the invoice lines for an invoice
You can follow the report_invoice.xml to print the lines.
<table class="table table-condensed">
<thead>
<tr>
<th>Description</th>
<th>Quantity</th>
<th class="text-right">Unit Price</th>
<th class="text-right" groups="sale.group_discount_per_so_line">Discount (%)</th>
<th class="text-right">Taxes</th>
<th class="text-right">Amount</th>
</tr>
</thead>
<tbody class="invoice_tbody">
<tr t-foreach="o.invoice_line" t-as="l">
<td><span t-field="l.name"/></td>
<td>
<span t-field="l.quantity"/>
<span t-field="l.uos_id" groups="product.group_uom"/>
</td>
<td class="text-right">
<span t-field="l.price_unit"/>
</td>
<td class="text-right" groups="sale.group_discount_per_so_line"><span t-field="l.discount"/></td>
<td class="text-right">
<span t-esc="', '.join(map(lambda x: x.name, l.invoice_line_tax_id))"/>
</td>
<td class="text-right">
<span t-field="l.price_subtotal"
t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
</td>
</tr>
</tbody>
</table>

Join 2 rows into one based on condition

I´m fairly new to SQL and can´t get this around my head and need some help!
My table look something like this:
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="307" colspan="3" valign="top">
<p>
<strong>Kompetens</strong>
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
<strong>Emp.nr</strong>
</p>
</td>
<td width="102" valign="top">
<p>
<strong>Code</strong>
</p>
</td>
<td width="102" valign="top">
<p>
<strong>EndDate</strong>
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
111
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
<p>
2015-01-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
111
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
222
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
<p>
2015-01-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
222
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
333
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
333
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-02
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
444
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
<p>
2015-01-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
444
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
</tbody>
</table>
I would like to merge into 1 row per employee where both Dansa1 and Dansa2 has a EndDate. Like this:
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="102" valign="top">
<p>
<strong>Emp.nr</strong>
</p>
</td>
<td width="102" valign="top">
<p>
<strong>EndDate</strong>
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
111
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
444
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
</tbody>
</table>
I also use a string variable to select wich employees to include:
SELECT [Emp.nr], [Code]
FROM [Kompetens]
WHERE [Emp.nr] IN #strEmp.nr
You wish to show only rows that have both entries, dansa1 and dansa2.
You can do so with group by, count and having:
SELECT [Emp.nr], max([EndDate])
FROM [Kompetens]
GROUP BY [Emp.nr]
HAVING count(*) > 1
Note: Like this, you don't precisely check if both rows have "Dansa1" and "Dansa2". It would also work if they had "Dansa1" twice. with max(), you select only the latest date.
Edit:
If you have rows that e.g. have no value in the field Code, then you can exclude them with the where clause, like this:
SELECT [Emp.nr], max([EndDate])
FROM [Kompetens]
WHERE Code IS NOT NULL AND Code != ""
GROUP BY [Emp.nr]
HAVING count(*) > 1
Where narrows the basis the aggregate functions are working with. Having narrows the result set created by the aggregate functions.
You can use group by . The query will look like :
SELECT [Emp.nr], [EndDate]
FROM [Kompetens]
group by [Emp.nr], [EndDate]