'Creating SQL queries from Query builder

I'm trying to automate query builder, I've managed to create simple queries however unable to create complex or joint queries. The simple query is hardcoded, looking to make it dynamic.

Attaching the image of the query builder for reference. Complex or joint queries to be something like this "StateID = 5 AND STATE = "Biharenter image description here"

Below is the code for reference: (simple queries)

public static void selectbyqueries() throws InterruptedException{
        String sname=null;
        //data queries
            //iterate through fields
            List<WebElement> rowsList = driver.findElements(By.xpath("//*[contains(@class,'textcolq')]"));
            Thread.sleep(1000);
            for (WebElement element : rowsList) {
                Thread.sleep(500);
                try {
                    sname = element.getText();
                    if (sname.equalsIgnoreCase("Number")) { //change the data type
                        Thread.sleep(1000);
                        element.click();
                        break;
                    }
                } catch (Exception e) { }
            }
            driver.findElement(By.xpath("//*[contains(text(),'GET UNIQUE VALUES')]")).click();
            //query tools
            List<WebElement> query = driver.findElements(By.xpath("//*[contains(@class,'inner-flex ng-star-inserted')]"));
            Thread.sleep(1000);
            for (WebElement element : query) {
                Thread.sleep(500);
                try {
                    sname = element.getText();
                    //will have to change the tool symbol (stand alone attributes)
                    if (sname.equalsIgnoreCase("=")) {
                        
                        highlightclick(element);
                        Thread.sleep(1000);
                        element.click();
                        break;
                    }
                } catch (Exception e) { }
            }
            //unique values
            List<WebElement> unique = driver.findElements(By.xpath("//*[contains(@class,'cursor selected-option ng-star-inserted')]"));
            Thread.sleep(1000);
            for (WebElement element : unique) {
                Thread.sleep(500);
                try {
                    sname = element.getText();
                    //will 
                    if (sname.equalsIgnoreCase("1")) {
                        highlightclick(element);
                        Thread.sleep(1000);
                        element.click();
                        break;
                    }
                } catch (Exception e) { }
            }
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source