亲爱的 Selenium Webdriver 专家,
我是这个框架的新手,需要一些关于如何从销售物业列表网站定位/查找所有搜索结果的建议。下面是一个工作代码,它使用 Selenium Webdriver 成功找到了所有属性,但我不知道如何使用 findElements(by...) 来获取该网站返回的每个结果:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.domain.com.au/?mode=buy");
// Enter the query string "3000"
WebElement query = driver.findElement(By.xpath(".//*[@id='ctl00_SearchMoreCriteria_Radar_searchToBuy']"));
query.sendKeys("3000");
WebElement searchButton = driver.findElement(By.xpath(".//*[@id='ctl00_SearchMoreCriteria_Radar_Search']"));
searchButton.click();
// Sleep until the div we want is visible or 5 seconds is over
long end = System.currentTimeMillis() + 5000;
有人可以就这个查询提供一些建议吗?我还想在定位/查找所有返回的结果之前包含一个暂停机制?
非常感谢,
杰克
非常感谢 Santoshsarma 的回复,但我正在努力将您的建议应用到以下返回的 Web 查询页面输出片段中:
<h3>
<a id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_hypAddress" href="/Property/For-Sale/Penthouse/VIC/Melbourne/?adid=2009775619">602/73 Flinders Lane, Melbourne</a></h3>
<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>
<dt class="bedrooms">Bedrooms</dt>
<dd id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_ddBedrooms" class="bedrooms" title="Bedrooms">3</dd>
<dt class="bathrooms">Bathrooms</dt>
<dd id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_ddBathrooms" class="bathrooms" title="Bathrooms">4</dd>
<dt class="carspaces">Car spaces</dt>
<dd id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_ddCarSpaces" class="carspaces" title="Car spaces">2</dd>
</dl>
</div>
<div class="main-wrap">
<ul class="photo cfix">
<li>
<a id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_hypMainThumb" tabindex="-1" class="contain" href="/Property/For-Sale/Penthouse/VIC/Melbourne/?adid=2009775619"><img id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_imgMainThumb" title="602/73 Flinders Lane, Melbourne" src="http://images.domain.com.au/img/2012625/18127/2009775619_1_PM.JPG?mod=120925-150000" alt="Main photo of 602/73 Flinders Lane, Melbourne - More Details" style="border-width:0px;" /></a>
</li>
<li class="last">
<a id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_hypSecondThumb" tabindex="-1" class="contain" href="/Property/For-Sale/Penthouse/VIC/Melbourne/?adid=2009775619"><img id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_imgSecondThumb" title="602/73 Flinders Lane, Melbourne" src="http://images.domain.com.au/img/2012625/18127/2009775619_2_PM.JPG?mod=120913-125823" alt="Photo of 602/73 Flinders Lane, Melbourne - More Details" style="border-width:0px;" /></a>
</li>
</ul>
列出 AllSearchResults=driver.findElements(By.id("ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl01_EliteListingTemplate_hypAddress"));
ctl01 中有一个索引需要循环获取所有搜索结果,根据其他类似威胁,搜索结果会很慢。有没有更好的方法在 WebElement 上使用 findElement() 来搜索它的孩子,但我不知道在哪里找到根。您是否能够确认这种方法是否有效?也许可以从以下 URL 查询结果页面确定结果列表的根:http: //www.domain.com.au/Search/buy/Property/Types/公寓单元公寓/复式/独立屋/新公寓楼花/新住宅设计/新房子土地/阁楼/半独立/工作室/露台/联排别墅/别墅/州/VIC/区域/内城/地区/墨尔本地区/郊区/墨尔本/?bedrooms=1&bathrooms=1&carspaces=1&from=450000&searchterm=3000&pois=PriSchl|1|2|2000
非常感谢您对我在这方面缺乏经验的耐心等待。