Selenium Webdriver エキスパートの皆様
Selenium Webdriver の文字列一致メソッドが、Java の次のコード スニペットで正しく機能しているかどうか疑問に思っています。
if (property.findElements(By.xpath("./dl[@class='cN-featDetails']/dd[matches(class,'propertytype type-house']")).size() > 0 ) { // line 229
以下は、行 229 が読み取っている xhtml Web ページです。
<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>
ただし、これにより次のエラーが発生しました。
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: "
私もmatches(class,'propertytype.*$']")
成功せずに試しました。
物件が戸建(type-house)かアパート(type-apart)かでクラスの名称が変わる……。
このプロパティタイプ要素に値/有効なツリーノードがあるかどうかを確認するために、一致で正規表現を使用する方法に関する提案はありますか?
このコード スニペットは、この URLを検索しています。
Windows XP および 7 プラットフォームで Selenium 2.25.0、Java 1.7.0_11 を使用しています。
アドバイスをいただければ幸いです。