0
votes

I am trying to click an image button, but i am getting org.openqa.selenium.NoSuchElementException. I even Checked if the element is present in any iframe by iterating through the frames. It is not present in any of the frames. Am i missing something?. Can someone please help me out with this.

Below is the code i am trying:

WebDriverWait wait2 = new WebDriverWait(driver,30);  
WebElement image = wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//tr//table[@title='User Prompt Input']//div[@id='IconImg_vertBar_leftPaneW_icon_3']")));  
actions.click(image).build().perform();

Exception i am getting:

Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 45 seconds waiting for visibility of element located by By.xpath: //tr//table[@title='User Prompt Input']//div[@id='IconImg_vertBar_leftPaneW_icon_3']
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'W1856237', ip: '192.168.43.137', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
    at com.ExpTestcases.TestOne.main(TestOne.java:105)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//tr//table[@title='User Prompt Input']//div[@id='IconImg_vertBar_leftPaneW_icon_3']"}
  (Session info: chrome=70.0.3538.77)

And this is the html code for the image button:

<table role="button" aria-label="User Prompt Input" aria-pressed="false" title="User Prompt Input" style="display: block; cursor: pointer;" false"="" margin:0px"="" id="vertBar_leftPaneW_icon_3" class="" cellspacing="0" cellpadding="0" border="0" aria-labelledby="ariaLabelledBy_vertBar_leftPaneW_icon_3" tabindex="0">
        <tbody>
            <tr valign="middle">
                <td id="iconleft_vertBar_leftPaneW_icon_3" class="">
                    <div style="width:2px;height:35px"></div>
                </td>
                <td id="iconmid_vertBar_leftPaneW_icon_3" align="center" style="height:35px;" class="">
                    <div style="overflow:hidden;height:31px;" valign="middle">
                    <div id="IconImg_vertBar_leftPaneW_icon_3" class="imo" style="width:31px;height:31px;background-image:url('images/main/vertbar_icons.png');background-position:-1px -127px;margin-top:2px;cursor:pointer"></div>
                    </div>
                </td>
                <td id="iconright_vertBar_leftPaneW_icon_3" class="">
                    <div style="width:2px;height:35px"></div>
                </td>
            </tr>
        </tbody>
    </table>

Xpath trials:

  • //table[@aria-label="User Prompt Input"]

  • //tr//table[@title='User Prompt Input']//div[@id='IconImg_vertBar_leftPaneW_icon_3']

  • //table[@aria-label="User Prompt Input"]/@title

  • //tr//table[@aria-label="User Prompt Input"]/@title

1
if running it only in selenium ide (and not web driver) is ok, you can use kantu's visual xclick (image of button) command and avoid debugging the xpath. - Fabrice Zaks

1 Answers

0
votes

As you are trying to invoke click() on the element so instead of using visibilityOfElementLocated() method you need to use elementToBeClickable() method and can use either of the following solutions:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("table[id^='vertBar_leftPaneW_icon_'][aria-label='User Prompt Input'] div.imo[id^='IconImg_vertBar_leftPaneW_icon_'][style*='vertbar_icons']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//table[starts-with(@id,'vertBar_leftPaneW_icon_') and @aria-label='User Prompt Input']//div[@class='imo' and starts-with(@id,'IconImg_vertBar_leftPaneW_icon_')][contains(@style,'vertbar_icons')]"))).click();