ratsstack
ratsstack

Reputation: 1021

Frustrating ElementNotVisibleException error

I am getting the following error when I attempt to click a button:

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

Command duration or timeout: 10.06 seconds

I've tried the following and none worked:

1) Waiting for 10 seconds in case the page is being loaded

2) Used JS executor thus:

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", By.cssSelector("#IconButton > input.IconButtonDisplay"));

3) Used wait until element is visible

Number 2 is actually executed but the results of the click don't eventuate i.e. new page does not open.

Number 3 times out stating button is not visible, but button is visible and can be manually clicked.

What I can tell you is that using the Selenium IDE I am able to playback and click the button no problems.

HTML of button (can't put too much here as proprietary information). Apologies for formatting:

<div widgetid="dijit__WidgetsInTemplateMixin_13" id="dijit__WidgetsInTemplateMixin_13" class="gridxCellWidget">
  <div class="IconButton" widgetid="IconButton" id="IconButton" data-dojo-type="ab.cd.ef.gh.IconButton" data-dojo-attach-point="rowBtn1Pt">
    <input class="IconButtonDisplay" src="/tswApp/ab/cd/ef/gh/images/edit.png" style="width: 20px;" type="image">
  </div>
</div>

Upvotes: 2

Views: 120

Answers (3)

ratsstack
ratsstack

Reputation: 1021

for me this is what worked:

   JavascriptLibrary jsLib = new JavascriptLibrary(); 
   jsLib.callEmbeddedSelenium(driver,"triggerMouseEventAt", editButton,"click", "0,0");

Hope this helps others who are having the same problem.

Upvotes: -1

JeffC
JeffC

Reputation: 25714

Have you tried just using FirefoxDriver?

FirefoxDriver driver = new FirefoxDriver();

Have you tried just using this? Is this not unique enough?

    driver.findElement(By.cssSelector("input.IconButtonDisplay")).click();

If not, try this (it's the equivalent to what you were doing with JSE)

    driver.findElement(By.cssSelector("#IconButton > input.IconButtonDisplay")).click();

Maybe it's not the INPUT that takes the click? Have you tried clicking either of the parent DIVs?

driver.findElement(By.id("IconButton")).click();

or

driver.findElement(By.id("dijit__WidgetsInTemplateMixin_13")).click();

Upvotes: 1

Saifur
Saifur

Reputation: 16201

In Javascript executor you want to pass the instance of WebElement not the By selector. So change

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();",   By.cssSelector("#IconButton > input.IconButtonDisplay"));

to

WebElement element = driver.findElement(By.cssSelector("#IconButton > input.IconButtonDisplay"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

Upvotes: 1

Related Questions