0

Issue - Getting 'Element is no longer attached to the DOM'

Approach - 1. Check if the element is displayed on the webpage 2. Trying to click the element

Code -

System.out.println("boolean value of Confirm order is" +driver.findElement(By.id("confirmOrder")).isDisplayed());
if (driver.findElement(By.id("confirmOrder")).isDisplayed() == true) {          driver.findElement(By.id("confirmOrder")).click();
//driver.findElement(By.id("confirmOrder")).sendKeys("{Enter}");
//actions.moveToElement(driver.findElement(By.id("confirmOrder"))).build().perform();
//actions.click().perform();
System.out.println("button clicked");
}

Output boolean value of Confirm order istrue button clicked

Tried couple of approaches but none seems to be working. Any help is appreciated.

Krishna S
  • 71
  • 3
  • 12
  • Also tried:-{driver.findElement(By.xpath("//input[@id='confirmOrder' and @class='confirmOrder']")).click();} – Krishna S Oct 31 '13 at 04:04
  • what line raises 'Element is no longer attached to the DOM'? – Furious Duck Oct 31 '13 at 09:52
  • @alexander-petrovich - I am not getting the error with this approach below but neither the button is getting clicked:-- 'System.out.println("Boolean value of button searched through xpath is" +driver.findElement(By.xpath("//input[@id='confirmOrder' and @class='btn btnPrimary']")).isDisplayed());' driver.findElement(By.xpath("//input[@id='confirmOrder' and @class='btn btnPrimary']")).click(); – Krishna S Oct 31 '13 at 14:51

2 Answers2

0

I think you are not using implicit or explicit waits, refer this for more info,a very neat explanation is provided on this issue...

Community
  • 1
  • 1
Amith
  • 6,818
  • 6
  • 34
  • 45
0

On Windows 7, certain web elements such as button doesn’t gets clicked using the below line of code:- driver.findElement(By.id("ButtonID")).click();

Tried using XPath as well but that didn’t used to work always.

Following is the thread that list down the issue with Windows 7: https://code.google.com/p/selenium/issues/detail?id=6112

This is the workaround:-

WebElement element = driver.findElement(By.id("ButtonID"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Krishna S
  • 71
  • 3
  • 12