如何获取Selenium Webdriver XPath </h5>中当前<h5>标记下的所有文本

时间:2013-03-21 12:42:35

标签: selenium-webdriver

我需要检索标记h5下面的所有文本值,但无法检索。以下是目标xhtml网页的一小部分:

<div class="s-prodDetails">
     <div class="description">

         <h4>CONTACT SALES AGENT FOR FURTHER INFORMATION </h4>
         <h5>LA’s finest penthouse apartment, now offered for sale</h5><p>The North Eastern Penthouse 28B, by Poco Design has consummate international appeal, offering 412sqm internal living space plus an exten...</p>
         <p class="contact"><strong>Contact</strong> Ron Smith, CBRE Residential Projects</p>
       </div> 
       <a href="/Property/For-Sale/Penthouse/LA/Gabriel/?adid=2010120948" class="button" id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_hypMoreDetails">More Details</a>

       <dl class="agent" id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_dlAgent">
            <dt>Advertiser</dt>
            <dd class="contain">
                <img style="border-width:0px;" src="http://images.abc.com.au/img/Agencys/14927/searchlogo_14927.GIF" title="CBRE Residential Projects" id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_imgAgencyLogo">
            </dd>
            <dt class="video">Advertiser video</dt>
            <dd class="video"></dd>
        </dl>
    </div>

以下是仅返回当前代码内容的代码段:

List<WebElement> allProperties = driverMainPage.findElements(By.xpath("//div[@class='feat-wrap']"));
    for (WebElement property : allProperties) {
        WebElement mainWrap = property.findElement(By.xpath("../div[@class='main-wrap']"));
         System.out.println("Sales description: " + MainWrap.findElement(By.tagName("h5")).getText());
    }

以下是2次XPath搜索但未成功:

System.out.println(mainWrap.findElement(By.tagName("h5")/child::text()));
System.out.println(mainWrap.findElement(By.tagName("h5")//child::text()));

我在Windows XP上使用Selenium Webdriver 2.x,Java 7&amp; 7个平台。

0 个答案:

没有答案