New python selenium phantomJS tab not working

I am using selenium with the PhantomJS webdriver, and I found that I cannot open a new tab using this web editor. I use the standard line:

driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't') 

I am using a Mac.

I also tried this with Firefox and it works.

Any help to get her working with PhantomJS would be appreciated!

+4
source share
1 answer

I had the same problem now, and I found a way that, in my opinion, is better than trying to send keys to PhantomJS.

Remember that PhantomJS is a browser without a browser - for your OS, a real window does not open with keyboard shortcuts.

, /, . .

( - ).

:

# Click a link that opens a new tab ...

# You'll see there a new window handle!
print(driver.window_handles)

# Switch to the new window handle in the window_handles list
driver.switch_to.window(driver.window_handles[1])

# Switch back to the original window
driver.switch_to.window(driver.window_handles[0])

current_url, , , :

assert "www.stackoverflow.com" in driver.current_url

: fooobar.com/questions/1579115/...

+6

All Articles