こんにちは、XpathとSeleniumを使ってFacebook内のすべての友達をフェッチしようとしています。問題は、すべての友だちを空リストに戻すときです。XpathとSeleniumを使用したアイテムのリスト
using System;
using System.Collections.Generic;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace Automation
{
class Program
{
static void Main(string[] args)
{
using (IWebDriver driver = new FirefoxDriver())
{
driver.Navigate().GoToUrl("https://mbasic.facebook.com");
IWebElement username = driver.FindElement(By.Name("email"));
username.SendKeys("email");
IWebElement password = driver.FindElement(By.Name("pass"));
password.SendKeys("password");
IWebElement submit = driver.FindElement(By.Name("login"));
submit.Submit();
var waitHomePage = new WebDriverWait(driver,TimeSpan.FromSeconds(10));
waitHomePage.Until(ExpectedConditions.ElementExists(By.PartialLinkText("Chat")));
IWebElement chat = driver.FindElement(By.XPath(".//*[@id='header']/div/a[6]"));
//driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
chat.Click();
IList<IWebElement> friends = chat.FindElements(By.ClassName("m br bs"));
}
}
}
}
Friends.Count return 0。ここで
は友人のHTMLは、私の知る限り、あなたのコード内のいくつかのミスを持っている(とHTML
あなたは提供が完全でないわけではない見ることができるようにリストに
<div class="bo bp bq">
<table class="m br bs">
<tbody>
<tr>
<td class="t bt">
<a class="bu" href="/messages/read/?fbid=100002640428096&click_type=buddylist#fua">Friend Name</a>
</td>
<td class="n bv">
<img class="bw bx s" src="https://fbstatic-a.akamaihd.net/rsrc.php/v3/yo/r/DbsprgIuYE0.png" width="7" height="14"/>
</td>
</tr>
</tbody>
<table class="m br bs">
<table class="m br bs">
<table class="m br bs">
</div>
</div>
ありがとうございました –
それは私のために働いていましたが、友人リストを取得するためのXpath式はこのようになります.//a [@ class = 'bu'] [contains(@ href、 'buddylist')] :) –