Can anybody help me out? I have an app which displays a popup as soon as the app (url) is launched. The popup contains images, text, checkbox and button. I can able to locate the checkbox and button using firebug but when I use the same in code to handle that, it get fails and throws an error as follows:

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"**//div[@class='modal-dialog']/div/div/button[@type='button']/span[text()]**"}

I have tried with ways as follows

  1. Alert-- but it is telling that not an alert
  2. Frame-- driver.switchTo().frame(0) is passed but after that the same error as above described
  3. XPath-- no use same error as above.

Note: It is an ecommerce app. Can anybody please help me out.

  • do you have android app? Commented May 29, 2015 at 6:32
  • It is a web application, i need to automate through selenium webdriver.
    – Bunny
    Commented May 29, 2015 at 6:34
  • can you please share all html code of that popup and page? Commented May 29, 2015 at 7:23
  • Code Snippet: <div id="overLayBoxPopup" class="overLayBoxPopup"> <form name="frmOverageConfirm" id="frmOverageConfirm" method="POST"> <div id="overageconfirm"> <div id="overageconfirm_header" class="header-data">Confirm your age </div> <div id="overageconfirm_content" class="content-data">
    – Bunny
    Commented May 29, 2015 at 9:50

1 Answer 1


If you use the driver.getWindowHandle(), this method returns only the handle for current window ( your main window). If another pop-up window opens, you will need to call Set<String> handles = driver.getWindowHandles() to return a list of all available handles. And then you call driver.switchTo().window(handles.get(handles.size() - 1)). This will switch to the last listed window handle.

  • Set <String>initial=driver.getWindowHandles(); returns only one string [{43169bda-89e2-4c83-ba01-b4f76e1ecdb6}]. can't switch to the same window right. After this statement I wrote driver.findElement(By.xpath(xpathexpr)).click(); which works fine. Here I don't know how it is handled, thank you anyways.
    – Bunny
    Commented May 29, 2015 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.