我在嘗試使用我的瀏覽器自動發佈評論。對於我提出這個代碼使用xpath和硒設置facebook註釋
static void Facebook()
{
var url = "http://facebook.com";
var email = "email";
var password = "password";
ChromeOptions options = new ChromeOptions();
options.AddArgument("--disable-notifications");
driver = new ChromeDriver(options);
driver.Url = url;
driver.Manage().Window.Maximize();
driver.FindElement(By.Id("email")).SendKeys(email);
driver.FindElement(By.Id("pass")).SendKeys(password + Keys.Enter);
driver.Url = "https://www.facebook.com/CsharpCorner/photos/a.487296564614322.115393.194086953935286/1572378532772781/?type=3&theater";
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
driver.FindElement(By.XPath(@"/html[@id='facebook']/body[@class='hasLeftCol _2yq home composerExpanded _5vb_ fbx _-kb s_v05quun15 chrome webkit win x1 Locale_en_US']/div[@id='photos_snowlift']/div[@class='_n9']/div[@class='_n3']/div[@class='fbPhotoSnowliftContainer snowliftPayloadRoot uiContextualLayerParent']/div[@class='clearfix fbPhotoSnowliftPopup']/div[@class='rhc photoUfiContainer']/div[@id='fbPhotoSnowliftDetails']/form[@id='u_4b_5']/div[@id='fbPhotoSnowliftFeedbackInput']/ul[@id='u_jsonp_3_18']/div[@id='addComment_1572378532772781']/div[@class='UFIMentionsInputWrap UFIStickersEnabledInput clearfix']/div[2]/div[@class='UFIImageBlockContent _42ef _8u']/div[@class='UFICommentContainer']/div[@class='_fmi UFIInputContainer']/div[@class='_2xwx _289c']/div[@id='composer_text_input_box']/div[@class='_5yk2']/div[@class='_5rp7']/div[@class='_5rpb']/div[@class='notranslate _5rpu']/div/div/div[@class='_1mf _1mj']"))
.SendKeys("123123");
Thread.Sleep(2000);
driver.Quit();
}
這workd完美,直到driver.findElement
我已經複製使用xpath helper chrome extension但可惜的是我得到錯誤
沒有這樣的元素的XPath:無法找到元素:。 ..
我該怎麼辦?
我們需要使用...動態xpath ....你能給我們DOM –
@santhoshkumar我有問題的網址。請參閱'driver.Url' – gsiradze
我已經登錄並點擊了網址。我得到了該帖子的放大視圖,我們是否需要點擊右側的「評論」按鈕進行評論? –