Issue
Scenario:
I have a WebTable where i go and enter the Search Criteria and based on the Search Criteria the Matching records appears. Then i Need to select 2 checkbox from the table .
My Question is - The Code has the option to select checkbox but i need to select any Two checkbox and Second after selecting the checkbox i need to come out of the Loop..And there could be 2 or more rows in the WebTable
Below is my Code:
List chekcboxoptions = driver.findElements(By.xpath("//label[contains(@class,'mat-checkbox-layout')]")); List DemandSelection = driver.findElements(By.xpath("//tbody[@role='rowgroup']//tr//td[contains(@class,'mat-column-demandId')]"));
for(WebElement demandselection:DemandSelection)
{
Random random = new Random();
int index = random.nextInt(chekcboxoptions.size());
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 100)");
chekcboxoptions.get(index).click(); = If i
insert a break after selecting one checkbox it comes out of the loop but i need to select two checkbox .
HTML OF THE Web Table:
Continue Back searchfilter_alt More Filters Demand ID Cargo OD / BU Load Port Discharge Port Laycan Start Date Laycan End Date GBPO Dead Line 4378SELTESTTECHMTESSINGAPOREHONGKONG2030-04-092040-06-152055-12-30 4379SELTESTTECHMTESSINGAPOREHONGKONG2030-04-092040-06-152055-12-30 4380SELTESTTECHMTESSINGAPOREHONGKONG2030-04-092040-06-152055-12-30 4381SELTESTTECHMTESSINGAPOREHONGKONG2030-04-092040-06-152055-12-30
Solution
Here, you should not iterate all the elements, just generate 2 random number and click the select option.
int randOne = random.nextInt(chekcboxoptions.size());
chekcboxoptions.get(randOne).click();
int randTwo = random.nextInt(chekcboxoptions.size());
chekcboxoptions.get(randTwo).click();
Do not use for loop for this
Answered By - Jayanth Bala
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.