I am clicking a link which takes me to new page, but I don't know how to proceed after that. When I try to find an element by id in the next page it gives me error:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"myid"} 

My code:

browser = webdriver.Firefox()

elem = browser.find_element_by_id('closeMessageButton') # Find the search box
elem.click() # this takes me to new link

# now I am searching id from new page
elem = browser.find_element_by_id('newpage_id')  #

I have seen this http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html but couldn't succeed in implementing for my case. I think the information in browser is not updated yet.

  • 1
    page? As in new browser tab or new window? You would need to switch to new window or tab to recognize that new element. Jul 14, 2015 at 2:41
  • Also you would need to implement some kind of wait, so that the script waits for some time, before jumping into new page and then finding element. Jul 14, 2015 at 2:42

3 Answers 3


The problem is that you don't switch to opened window, and webdriver searches for elements in the old page instead of the newly opened one.


String winHandleBefore = driver.getWindowHandle();
        for(String winHandle : driver.getWindowHandles()){

This java method's part switches to the newest window. Also consider maximizing it, because sometimes tests masses up in not maximized windows. Another point: waiting. Try to read here about different types of wait. Good luck.

  • thank you ,this is useful for me may i know how to write this sample code
    – user41695
    Sep 26, 2019 at 13:29

Solution for Python. This code will switch to the second window in your browser.

window_after = driver.window_handles[1]
  • It is important to note that the new handle will not be available until after then new page starts to open - hence you may need a Wait. Mar 21, 2022 at 16:26

After navigating to the new page if you want to do something on that new page

newURl = driver.window_handles[0]


After doing this you can do something in the new url without getting "no such element exceptions"

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