Issue
I have a web element that when double-clicked, gives access to the dropdown. I am trying to use a do-while loop to achieve this but the web element needs one two or three double-click attempts to have dropdown being enabled.
do {
ButtonAndMouseActions.doubleClickOnButton(driver,starSecurityHolderTypeValues.get(0));
}
while (holderTypeDropdown.get(0).isDisplayed());
In while
condition, the holderTypeDropdown
is not displayed and it lands me in the holder type dropdown element not visible exception and my code is not executed further. I want to double-click on starSecurityHolderTypeValues
until that `holderTypeDropdown is displayed.
Solution
It seems like you want to perform a double click on a button until a certain condition (in this case, the visibility of holderTypeDropdown) is met. You can achieve this by modifying your code slightly. Instead of using a do-while loop
, you can use a while loop
with a condition to check if the holderTypeDropdown is not displayed.
If it's not displayed, perform the double click;
otherwise, exit the loop.
int maxAttempts = 3;
int attemptCount = 0;
while (!holderTypeDropdown.get(0).isDisplayed() && attemptCount < maxAttempts) {
ButtonAndMouseActions.doubleClickOnButton(driver, starSecurityHolderTypeValues.get(0));
attemptCount++;
}
// Further code after the loop (e.g., interacting with the dropdown when it is displayed)
if (holderTypeDropdown.get(0).isDisplayed()) {
// Your code to interact with the dropdown
} else {
// Code to handle the case when the dropdown is still not displayed after max attempts
System.out.println("Dropdown not displayed after " + maxAttempts + " attempts.");
}
In this code snippet, the loop will continue as long as holderTypeDropdown
is not displayed and the number of attempts is less than the maximum allowed attempts (maxAttempts
). If the dropdown becomes visible or the maximum attempts are reached, the loop will exit, and you can handle the scenario accordingly.
Answered By - Eira
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.