0

After reading and learning tons of stuff from Stackoverflow, I finally have a question that I can't seem to find an answer to.

I am using Python, Selenium (WebDriver) and Chrome to write some test scripts. In the course of one of the scripts, a link has to be clicked which opens a PDF doc in a new Chrome window. All this is fine, as the new window pops up exactly the way it is supposed to, however, I cannot figure out how to get my code to work with the new window.

wd = WebDriver()
...

my_link = wd.find_elements_by_css_selector('a')[0]
my_link.click()     #will open the link target in a new window

I have tried to do things like:

new_wd = WebDriver()
new_wd = my_link.click()

and that doesn't work

and I have also:

new_wd = WebDriver()
new_wd.get(my_link.get_attribute('href')

which doesn't work because the new chrome window isn't logged in like the originating window.

I am not sure what to do here, and have been looking for answers for a while. Thanks


So the answer to this ends up being that I cannot get the new window.

What I ended up doing was building a list of the links that I need to go to along with their href's. Then instead of clicking those links, I iterated through the list with wd.get(listHref) and then going back to the original URL. This approach met my requirements so I am going with it.

Thanks for the help.

  • Is it a possibility to go to that page in the current window? That would be the quickest solution. Otherwise you could grab the current cookies from the existing webdriver and set them in the new webdriver so you are logged in there as well. Assuming cookies are set. – Bob Jun 26 '14 at 17:46

1 Answers1

0

In order to move to the new window you would need to get the window handle of the new window and switch to it. Here is the link How to handle the new window in Selenium WebDriver using Java? Although the code uses JAVA but python should be similar.

Community
  • 1
  • 1
SENoob
  • 36
  • 2