EDIT: I have updated my question and I know that I can increase the loop instead of 4 to 12 but the reason I have separate three for-loop is due to that; after iterating first loop i have to click carousel in order to go to the next next iteration as you can see my updated code. – sorry somehow i missed the code while copy/pasting.
I want to iterate through the rows, the total rows I have is 3 and every row has 4 columns, for an example:
row 1 has 4 columns
row 2 has 4 columns
row 3 has 4 columns
I have created 3 separate for-loop and my code works but I believe there is room to improve my code, can it have in one loop instead of three?
here is the code:
//first row
for (int j = 0; j < 4; j++)
{
string _image = String.Format("id('gen{0}')/a[{1}]/img", j, "1");
string _text = String.Format("id('gen{0}')/a[{1}]", j, "2");
...........
WaitForElement(By.XPath(_text)).Click();
}
_carouselDot = String.Format("id('HomePage1_Carousel1')/div/ul/li[{0}]/a", 2);
WaitForElement(By.XPath(_carouselDot)).Click();
//second row
for (int j = 4; j < 8; j++)
{
string _image = String.Format("id('gen{0}')/a[{1}]/img", j, "1");
string _text = String.Format("id('gen{0}')/a[{1}]", j, "2");
...........
WaitForElement(By.XPath(_text)).Click();
}
_carouselDot = String.Format("id('HomePage1_Carousel1')/div/ul/li[{0}]/a", 3);
WaitForElement(By.XPath(_carouselDot)).Click();
//third row
for (int j = 8; j < 12; j++)
{
string _image = String.Format("id('gen{0}')/a[{1}]/img", j, "1");
string _text = String.Format("id('gen{0}')/a[{1}]", j, "2");
...........
WaitForElement(By.XPath(_text)).Click();
}
What’s wrong with this –