0

I currently am working with a java/selenium project (written by another dev) where we loop through and excel sheet for the elements and their attributes and perform an action based on the condition (click, mousehover, etc). There is one button element that when clicked, it gets disabled, shows a different text while executing, then stays disabled but once data is loaded to a webpage, the button Text goes back to the original while staying disabled. See below for the snapshot of before click, after click and waiting for data to load, and after data is loaded along with the xpath of the element:

Before:

enter image description here

While waiting: enter image description here

After data is loaded and process complete: enter image description here

I have code below that works for performing the necessary actions based on the webElementType, since this is a button. What I would like is to be able to wait until this button says "Apply Filter" and still has the disabled attribute to it. How can I do that using java and selenium? See below code where click(element) is called where I am looking to wait for this specific scenario:

public void performAction() throws Throwable {
    List<Locator> allLocators = this.eachWebElement.getAllPossibleLocators();
    String webElementType = this.eachWebElement.getElementType();
    String logText = "";
    try {
        WebElement element = getSuitableWebElement(allLocators);
        List<WebElement> allElements = getSuitableWebElements(allLocators);
        if (webElementType.equalsIgnoreCase("textBox")) {
            logText = "to enter  " + this.eachWebElement.getInputValue() + " in "
                    + this.eachWebElement.getElementName() + " ";
            //                  System.out.println("TEXT BOX - Execute Step : " + this.eachWebElement.getElementName());
            enterText(element, this.eachWebElement.getInputValue().trim());
            //                  ExtentCustom.eachTest.log(Status.PASS, MarkupHelper.createLabel(logText, ExtentColor.GREEN));
            ExtentCustom.eachTest.pass(MarkupHelper.createLabel(logText, ExtentColor.GREEN));
        } else if ("radiobuttoncheckboxbuttonlink".contains(webElementType.toLowerCase())) {
            logText = "to click on " + this.eachWebElement.getElementName() + " ";
            //                  click(getSuitableWebElement(allLocators));
            click(element);
            //                  ExtentCustom.eachTest.log(Status.PASS, MarkupHelper.createLabel(logText, ExtentColor.GREEN));
            ExtentCustom.eachTest.pass(MarkupHelper.createLabel(logText, ExtentColor.GREEN));
        } else if (webElementType.equalsIgnoreCase("movemouse")) {
            logText = " mouse is moved to " + this.eachWebElement.getElementName();
            //                  moveMouse(getSuitableWebElement(allLocators));
            //                  System.out.println(" mouse is moved to ");
            moveMouse(element);
            //                  ExtentCustom.eachTest.log(Status.PASS, MarkupHelper.createLabel(logText, ExtentColor.GREEN));
            ExtentCustom.eachTest.pass(MarkupHelper.createLabel(logText, ExtentColor.GREEN));
        } else if (webElementType.equalsIgnoreCase("fileupload")) {
            logText = " file is uploaded to " + this.eachWebElement.getElementName();
            //                  moveMouse(getSuitableWebElement(allLocators));
            //                  System.out.println(" fileupload code " + this.eachWebElement.getInputValue());
            //                  System.out.println(allLocators);
            uploadFile(element, this.eachWebElement.getInputValue());
            //                  ExtentCustom.eachTest.log(Status.PASS, MarkupHelper.createLabel(logText, ExtentColor.GREEN));
            ExtentCustom.eachTest.pass(MarkupHelper.createLabel(logText, ExtentColor.GREEN));
        } else {
            boolean selectedStatus = selectFromDropdown(allElements, this.eachWebElement.getInputValue().trim());
            Assert.assertTrue(selectedStatus, this.eachWebElement.getInputValue().trim() + " not able to select, might be element value to select is wrong");
            logText = "value " + eachWebElement.getInputValue().trim() + " got selected from the dropdown : "
                    + this.eachWebElement.getElementName();
            //              ExtentCustom.eachTest.log(Status.PASS, MarkupHelper.createLabel(logText, ExtentColor.GREEN));
            ExtentCustom.eachTest.pass(MarkupHelper.createLabel(logText, ExtentColor.GREEN));
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        // ExtentCustom.logResult(reportStatusLogger, logText);
    }
}
wheelerlc64
  • 435
  • 2
  • 5
  • 17
  • Seems you are following Keyword Driver Framework. Is it fine if we just give a solution in normal way? One advise, you need to reconsider using Keyword Driver, buddy. It will hit on your scalability and flexibility. Take this with a pinch of salt. – Ahamed Abdul Rahman Jun 25 '23 at 04:02

1 Answers1

0

This may not be the final solution. Remember, I don't have the working UI too to look upon. Will try to help you based on your response.

From what I understood, we need to

  1. Wait for "Apply Filter" to get changed to "Searching Product...".

  2. Then wait for "Searching Product..." to become invisible (Optional)

  3. Then wait for "Apply Filter" to appear again.

     WebDriverWait webDriverWait = new WebDriverWait(driver, Duration.ofSeconds(30));
     webDriverWait.until(visibilityOfElementLocated(By.xpath("//div[starts-with(normalize-space(),'Searching Product')]")));
     webDriverWait.until(invisibilityOfElementLocated(By.xpath("//div[starts-with(normalize-space(),'Searching Product')]"))); //This can be removed if works without it.
     webDriverWait.until(visibilityOfElementLocated(By.xpath("//div[starts-with(normalize-space(),'Apply Filter')]")));
    

Please let me know if any problem occurs.

Ahamed Abdul Rahman
  • 512
  • 1
  • 5
  • 18