Dear Selenium Webdriver Experts,
I am wondering whether the string matches method in Selenium Webdriver is working properly with the following code snippet in Java:
if (property.findElements(By.xpath("./dl[@class='cN-featDetails']/dd[matches(class,'propertytype type-house']")).size() > 0 ) { // line 229
Below is the xhtml webpage where line 229 is reading from:
<dl class="cN-featDetails">
<dt class="proptype">Property type</dt>
<dd id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_ddPropertyType" class="propertytype type-house" title="Property type: House">House</dd>
However, this resulted in the following error:
Address: 28B/171 Gloucester Street, Sydney
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector ./dl[@class='cN-featDetails']/dd[matches(class,'propertytype type-house'] is either invalid or does not result in a WebElement. The following error occurred:
[InvalidSelectorError] Unable to locate an element with the xpath expression ./dl[@class='cN-featDetails']/dd[matches(class,'propertytype type-house'] because of the following error:
[Exception... "The expression is not a legal expression." code: "51" nsresult: "0x805b0033 (NS_ERROR_DOM_INVALID_EXPRESSION_ERR)" location: "
I have also tried matches(class,'propertytype.*$']")
without success either.
The name of class changes depending on whether the property is a house (type-house) or apartment (type-apartment)…..
Any suggestion on how to use regex in matches to check whether there is value / valid tree node in this property type element?
This code snippet is looking up this URL.
I am using Selenium 2.25.0, Java 1.7.0_11 on Windows XP & 7 platforms.
Your advice would be much appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…