Selenium IDE selecting from the list which is powered by Google - selenium

I'm new to Selenium IDE and I need to run some test on one website. Everything seems to work just fine except the part where I need to select my location since that list is powered by Google I can't really get the object by list id..
Here's my test so far:
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=newregister-form-email</td>
<td>javascript{"test+" + Math.floor(Math.random()*11111) + "#gmail.com";}</td>
</tr>
<tr>
<td>type</td>
<td>id=newregister-form-pass</td>
<td>test</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=input.submitLogin</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad(1000)</td>
<td></td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=u_users-form-name</td>
<td>Tester</td>
</tr>
<tr>
<td>type</td>
<td>id=u_users-form-surname</td>
<td>Test</td>
</tr>
<tr>
<td>type</td>
<td>id=u_users-form-phone</td>
<td>javascript{"+3706" + Math.floor(Math.random()*11111);}</td>
</tr>
<tr>
<td>type</td>
<td>id=cityinput</td>
<td>Vilnius</td>
</tr>
<tr>
<td>pause</td>
<td>1000</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=cityinput</td>
<td>Vilnius</td>
</tr>
The last part is where I need to choose from the dropdown list but Selenium IDE doesn't see it when recording.
Thank you in advance
Update:
This is html code of the city input :
<div class="row field">
<div class="col-xs-12 col-sm-8 col-sm-offset-4 col-md-offset-3 formelement-wrapper">
<input type="text" id="u_users-form-country" name="u_users-form[country]" value="" />
</div>
</div>
<div class="row field">
<div class="col-xs-12 col-sm-8 col-sm-offset-4 col-md-offset-3 formelement-wrapper">
<input type="text" id="u_users-form-city" name="u_users-form[city]" value="" />
</div>
</div>
<div class="row field">
<div class="col-xs-12 col-sm-8 col-sm-offset-4 col-md-offset-3 formelement-wrapper">
<input type="text" id='cityinput' placeholder="Miestas, Šalis">
</div>
</div>

instead of a pause you should use a waitForElementPresent on id=cityinput. This will allow you to wait until that element is present and not just 1 second (as your pause is currently doing)
<tr>
<td>waitForElementPresent</td>
<td>id=cityinput</td>
<td></td>
</tr>

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>')

Select all tables and exclude the div

I'm trying to do some stuff with python and selenium but I can't get my xpath to work. I have the following code :
<div id="ctl00_Main_treeCategories">
<table>
<tbody>
<tr>
<td><a id="ctl00_Main_treeCategoriesn0">Online Catalogus</a></td>
</tr>
</tbody>
</table>
<div id="ctl00_Main_treeCategoriesn0Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tbody>
<tr>
<td>
<div style="width:20px;height:1px"></div>
</td>
<td>
<a id="ctl00_Main_treeCategoriesn1">Dakraam</a>
</td>
</tr>
</tbody>
</table>
<div id="ctl00_Main_treeCategoriesn1Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tbody>
<tr>
<td><div style="width:20px;height:1px"></div></td>
<td><div style="width:20px;height:1px"></div></td>
<td></td>
<td class="treeNode ctl00_Main_treeCategories_2"><a class="ctl00_Main_treeCategories_0 treeNode ctl00_Main_treeCategories_1">Dakraam Duette® & Plissé Saaaaahade</a></td>
</tr>
</tbody>
</table>
</div>
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td>
<td></td>
<td class="treeNode ctl00_Main_treeCategories_2" style="white-space:nowrap;">
<a class="ctl00_Main_treeCategories_0 treeNode ctl00_Main_treeCategories_1">Duette® Fixé & Plissé Shadeeeee</a>
</td>
</tr>
</tbody>
</table>
</div>
I try to select all tables within the ctl00_Main_treeCategoriesn0Nodes div, and exclude the div on the first level within (ctl00_Main_treeCategoriesn1Nodes).
I tried :
//*[contains(#id, "ctl00_Main_treeCategoriest")]/div/table/
but this gives a syntax error.
You had two errors on the XPath:
Mispelling of the id (that t at the end)
Trailing / (not necessary)
//*[contains(#id, "ctl00_Main_treeCategories")]/div[not(#id="ctl00_Main_treeCategoriesn1Nodes")]/table
Demo: https://3v4l.org/SusIZ
Edit: Excluded inside ctl00_Main_treeCategoriesn1Nodes divs

How to select radio button in selenium web driver java using text of nearby element in XPath

I need to select radion button with id="optProfile" in 7th tr using text "Internet Users" in td/font tag. I am using below code but it is not working and selecting radio button from 1st tr row. Can anyone help
<html>
<head>
<body onmousedown="infCheckMouseDown(event);" onkeydown="infCheckDownKey(event);" onbeforeunload="INFIEExit();" onload="INFsetInitialFocus();window_onload();CreateScriptingFrames();">
<form action="PEINFCommon.ASP?WCI=Genericcreen&WCE=GenericEvent" onsubmit="return false" name="Genericcreen" method="post">
<table class="TopLevelTable" align="center" width="100%" border="0">
<tbody>
<tr>
<td width="100%">
<table width="100%" border="0">
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<td width="100%">
<div align="center">
<center>
<table width="98%" cellspacing="0" cellpadding="0" border="0" cols="1">
<tbody>
<tr align="center">
<td align="left">
<table width="100%">
<tbody>
<tr>
<tr>
<tr>
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<td width="5%">
<input id="optProfile" type="Radio" callfunction="" value="" onblur="ResetScript(this);return true;" onfocus="HighlightScript(this);" onclick="" name="" size="11">
<font class="fLabel"></font>
<br>
<input id="hidCurrentProfile" type="hidden" onblur="ResetScript(this);" onfocus="HighlightScript(this);" value="N" callfunction="" size="11" name="/Root/ACORD/InsuranceSvcRs/nk_ck_com.cc_FetchUserProfileRs/nk_ck_com.cc_SecurityDetails/nk_ck_com.cc_AvailableProfile[12]/nk_ck_com.cc_CurrentProfileInd">
<input id="hidProfile" type="hidden" onblur="ResetScript(this);" onfocus="HighlightScript(this);" value="RACINTER" callfunction="" size="11" name="/Root/ACORD/InsuranceSvcRs/nk_ck_com.cc_FetchUserProfileRs/nk_ck_com.cc_SecurityDetails/nk_ck_com.cc_AvailableProfile[12]/nk_ck_com.cc_ProfileCd">
</td>
<td>
<font class="">Internet Users</font>
</td>
</tr>
<tr height="">
<tr height="">
<tr height="">
<tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</center>
</div>
</td>
</tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
</frame>
<frame id="Script" scrolling="Yes" frameborder="0" noresize="">
</frameset>
</html>
you need to use ancestor instead of preceding:
//font[text()='Internet Users']/ancestor::tr[1]/td/input[#type='Radio']
and it's also a better practice to tell which one of the tr-ancestors you want -> [1] - since you want the first direct ancestor
Is there a reason why you are not using the id of the radio button?
WebElement wElement = wDriver.findElement(By.Id("optProfile"));
You can use the following XPath
//tr[.//font[text()='Internet Users']]//input[#id='optProfile']
This xpath looks for the tr containing the font tag with text "Internet Users" and then navigates to the input tag with id = 'optProfile'
You can use preceding as below-
By.xpath("//font[contains(text(),'Internet Users')]/preceding::input[#id='optProfile']")
Thanks everyone here for your help. I really appreciate it.Its working with below code
WebElement trs = GlobalVar.wDriver.findElement(By.xpath("//font[text()='Internet Users']/ancestor::tr[1]"));
trs.findElement(By.id("optProfile")).click();
I would try something like this
List<WebElement> trs = driver.findElements(By.cssSelector("table > tr"));
for (WebElement tr : trs)
{
List<WebElement> fonts = tr.findElements(By.tagName("font"));
if (!fonts.isEmpty() && fonts.get(0).getText().trim().equals("Internet Users"))
{
tr.findElement(By.id("optProfile")).click();
break;
}
}
You didn't show the TABLE tag in the HTML snippet so you will likely need to be more specific in the initial CSS selector. Basically this code loops through the TRs looking for "Internet Users" in the FONT tag. Once it finds it, it click the radio button with id=optProfile.
If you will post the TABLE tag in the HTML snippet I can help with the CSS selector.
Edit 1: changed the code to address the case where some TRs don't contain FONT tags.

selenium not finding correct link using xpath

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