3

I could reach all elements by driver.findElement() function. Tree elements were created using dhtmlx library and when I try to reach them I get NoSuchElementException.

I tried to reach by id, xpath, class, text, etc. but none of them worked for me. I also tried implicit waiting and Thread.sleep() methods but the result is the same.

 > <tr> <td class="standartTreeImage"> <img border="0" align="absmiddle"
    > style="padding: 0px; margin: 0px; width: 18px; height: 18px;"
    > src="http://marduk:5543/atlas/themes/third_party/dhtmlx/dhtmlxTree/codebase/imgs/vse_datasources/plus3.gif">
    > </td> <td width="20px" style="display: none;"> <img align="absmiddle"
    > src="http://marduk:5543/atlas/themes/third_party/dhtmlx/dhtmlxTree/codebase/imgs/vse_datasources/iconUncheckAll.gif"
    > style="width: 16px; height: 16px;"> </td> <td
    > class="standartTreeImage" style="width: 18px;"> <img border="0"
    > align="absmiddle" style="padding: 0px; margin: 0px; width: 18px;
    > height: 18px;"
    > src="http://marduk:5543/atlas/themes/third_party/dhtmlx/dhtmlxTree/codebase/imgs/vse_datasources/folderClosed.gif">
    > </td> <td class="standartTreeRow" nowrap="" style="width: 100%;
    > font-size: 10pt; cursor: pointer;"> <span class="standartTreeRow"
    > style="padding-left: 5px; padding-right: 5px;">hr-istanbul [15]</span>
    > </td> </tr>

For example one of them is this: I need to click the first td. Only locator is the image but I can not access the element .. NoSuchElementException.

element = driver.findElement(By.xpath("//img[contains(@src,'http://marduk:5543/atlas/themes/third_party/dhtmlx/dhtmlxTree/codebase/imgs/vse_datasources/plus3.gif')]"));

Also tried to reach last column element it didnt work either.

element = driver.findElement(By.xpath("//*[contains(text(), 'hr-istanbul [15]')]"));

1 Answers1

1

If you are getting NoSuchElementException as your provided exception, There may be following reasons :-

  • May be you are locating with incorrect locator, So you need to share HTML for better locator solution.

  • May be when you are going to find element, it would not be present on the DOM, So you should implement WebDriverWait to wait until element visible as below :-

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(byObject));
    
  • May be this element is inside any frame or iframe. If it is, you need to switch that frame or iframe before finding the element as below :-

    WebDriverWait wait = new WebDriverWait(driver, 10);
    
    //Find frame or iframe and switch
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("your frame id or name"));
    
    //Now find the element 
    WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(byObject));
    
    //Once all your stuff done with this frame need to switch back to default
    driver.switchTo().defaultContent();
    
Saurabh Gaur
  • 21,274
  • 8
  • 42
  • 69