I am currently running one script where there is a search box and I am entering some keywords in it and searching for the result. All the keywords are coming from excel sheet one by one so I have used "for loop" to achieve this. Now in this loop first time when I search for keyword, in next step, I have to click on one element which I already have written in my script however when loop runs second time, I don't need to click on that element because it is already clicked, now my script is getting failed because in the second time webdriver is not able to click on that element, I have tried with isdisplayed(), isenalbled() function but nothing is working. so what could be the best option to skip one step of click in loop from the second time. I know the last option to achieve this will be try catch but I dont want to use it, please suggest
When your button get clicked for first time , use one boolean variable and assign true to it. When second time loop runs and find that boolean variable is true or not and if yes then use "continue;" in your java code.
boolean isClicked = false;
For(int i=0; i<=some_value;i++) {
if(!isCliecked){
WebElement.clicked Searchbox.sendkeys("mykeywords") }
isClicked = true;
}else{
continue;
}