Reputation: 227
I have a Method for finding the element via Xpath and perform Click action but if element is available on Next page how can i do that ? I know i can find the xpath for next page and click it and look through it . But i want to come back to initial page as well.
For example I have 20 Elements found by xpath:
IList<IWebElement> Test= SeleniumDriver.WebDriver.FindElements(By.Xpath(""));
and if above will find 20 elements then i m running foreach loop. SO it can able to do all action as i needed but if first page got only 10 element then how can i go to next page for to find the remaining ones . Also in "Test" i'm not getting all the elements in order. So my foreach loop will find first 2 and might be 3rd one it tries to find will go to next page so i have to go to next page and find the element , validate it and then come back to initial page .
Please let me know if any easy way ?
Upvotes: 1
Views: 3905
Reputation: 2703
If you have table with information you will have button to next page (if it exist) so what you need to do is taking the elements like you did in while loop and check if next button exist if yes click on it and repeat taking the elements until button is exist
the best way is doing it by (pseudocode):
do
{
IList<IWebElement> Test= SeleniumDriver.WebDriver.FindElements(By.Xpath(""));
//HERE YOU CHECK IF BUTTON EXIST
if(isElementPresented(By.Id("")))
{
driver.FindElement(By.Id("")).Click;
}
else
{
//if button not exists
buttonExist = false;
}
}while(buttonExist);
Upvotes: 1
Reputation: 5667
You can write logic something like this
IList<IWebElement> Test= SeleniumDriver.WebDriver.FindElements(By.Xpath(""));
for each WebElement ele {
if(isElementPresent(ele) {
do Operation with ele
}
else {
go to second page
}
if(isElementPresent(ele)
do Operation with ele
Go to 1st page
}
Upvotes: 1