Sometimes in Selenium 2 after clicking on some element, it does not execute actual click (but does not throws error that element is not found), cann't find element from next page and therefore throws this exception:
First, you should check that there is no element with same selector and it does not tries to click some div. Second, I found that sometimes if there is floating div, especial over your links or buttons, it cann't properly click it. In latter case, best solution for form buttons is to use submit, instead of click, like:
Unable to locate element: {"method":"class name","selector":"alert"} For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.2.0', revision: '13073', time: '2011-07-26 00:54:48' System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_24' Driver info: driver.version: RemoteWebDriver
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"alert"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.2.0', revision: '13073', time: '2011-07-26 00:54:48'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_24'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:405)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:193)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByClassName(RemoteWebDriver.java:250)
at org.openqa.selenium.By$ByClassName.findElement(By.java:349)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:185)
at org.openqa.selenium.WebDriver$findElement.call(Unknown Source)
...
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"class name","selector":"alert"}
Build info: version: '2.2.0', revision: '13073', time: '2011-07-26 00:54:48'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_24'
Driver info: driver.version: unknown
First, you should check that there is no element with same selector and it does not tries to click some div. Second, I found that sometimes if there is floating div, especial over your links or buttons, it cann't properly click it. In latter case, best solution for form buttons is to use submit, instead of click, like:
driver.findElement(By.id("update")).submit();
Another thing that helps - especially with links, is to remove overflowing div (closing it - depends on your application logic) and waiting for second, like:Thread.sleep(1000);