Reputation: 1934
I am trying to navigate through a page and start adding to cart all products from the list. By doing that i want to click whatever it has the button "Agree".
Here is my code
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("url.com");
for (int i = 0; i < 10; i++)
{
driver.FindElement(By.LinkText("Agree")).Click();
}
Here is a screenshot with my buttons and their details in "Inspect"
Upvotes: 0
Views: 94
Reputation: 1187
As long as you're happy that you just click each of the found elements up to 10, then this will work.
var buttons = driver.FindElements(By.LinkText("Buy")).ToArray();
for (int i = 0; i < 10; i++)
{
buttons[i].Click();
}
Alternatively if you want to click each button once use a foreach
foreach(button in buttons)
{
button.Click();
}
Upvotes: 1