在Visual Studio中編寫Selenium WebDriver的代碼時,同一按鈕的這兩個代碼只能正常工作一次。單擊具有相同CssSelector或相同XPath的所有元素FindElements
點擊按鈕通過CSS選擇器:
driver.FindElement(By.CssSelector(".follow-text")).Click();
點擊按鈕與XPath:
driver.FindElement(By.XPath("//button[@class='user-actions-follow-button js-follow-btn follow-button btn small small-follow-btn']")).Click();
直到這個正確的...
但我想點擊所有按鈕不只是第一個,並且由於FindElements
(複數)讓我錯誤,我怎麼能點擊所有按鈕與相同的代碼?
使用此得到錯誤:
List<IWebElement> textfields = new List<IWebElement>();
driver.FindElement(By.XPath("//button[@class='user-actions-follow-button js-follow-btn follow-button btn small small-follow-btn']")).Click();
driver.FindElement(By.XPath("//button[@class='user-actions-follow-button js-follow-btn follow-button btn small small-follow-btn'][3]")).Click();
見捕獲:
我在嘗試,然後我現在鏈接一個捕獲,謝謝 – Lion6