0

I am getting error message unable to locate element even it is selected from DD

My Element is dynamic.

I have tried this way,

         static class GroupCount {
                    private static int i = 1;

                    static void inc() {
                        i++;
                    }

                    static int get() {
                        return i;
                    }
                }

                String xpathGroupSelect = "//*[@id='groupPicker" +
                                    GroupCount.get() + "-list']//div[contains(concat(' ','x-combo-list-item', ' '), 'x-combo-list-item') " +
                                    "and contains(text(),'"
                                    + name + "')]";

         WebElement group = driver.findElement(By.xpath(xpathGroupSelect));

     if (xpathGroupPick.isDisplayed()) {

                    WebDriverWait wait = new WebDriverWait(driver, 30);

                     wait.until(ExpectedConditions.elementToBeClickable(group)).click();


                    group.click();

WorkflowAction.addApprovers("Compliance");

I am trying to find 'compliance' element

Here is my html code:

> <div class="x-combo-list-inner" id="groupPicker1-list" style="width:
> 218px; margin-bottom: 8px; height: 81px;">    <div
> class="x-combo-list-item" style="">APPROVAL</div> <div
> class="x-combo-list-item" style="">Compliance</div>   <div
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
sapana
  • 37
  • 1
  • 10

1 Answers1

0

To locate the element with text as Compliance you to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following Locator Strategies:

  • cssSelector:

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.x-combo-list-inner[id^='groupPicker'] div:nth-child(2)")));
    
  • xpath:

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='x-combo-list-inner' and starts-with(@id, 'groupPicker')]//div[@class='x-combo-list-item' and text()='Compliance']")));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352