public void FindPrice()
{
IWebDriver driver_ = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());
driver_.Navigate().GoToUrl("http://www.momoshop.com.tw");
driver_.FindElement(By.CssSelector("#keyword")).SendKeys(this.SearchKeyWord_);
driver_.FindElement(By.CssSelector(".inputbtn")).Click();
Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();
try
{
if (driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count == 0)
{
ReadProductDetail(driver_.Url, ref info);
}
else
{
var PageCount = driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count;
for (var CurrentPage = 1; CurrentPage <= PageCount;)
{
List<IWebElement> products = driver_.FindElements(By.XPath("//*[@id=\"chessboard\"]/li/a")).ToList();
foreach (var product in products)
{
ReadProductDetail(product.GetAttribute("href"), ref info);
}
//Last Page
if (CurrentPage == PageCount)
{
break;
}
//Next Page
++CurrentPage;
driver_.FindElement(By.XPath(string.Format("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li[{0}]/a", CurrentPage))).Click();
}
}
}
catch (NoSuchElementException)
{
}
this.ProductDetail_.Add("momo", info);
driver_.Quit();
if (LocalDriver_ != null)
{
LocalDriver_.Quit();
}
return;
}