在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