本文介绍了在硒中控制Firefox的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据 window_handles
。
According to the window_handles
documentation:
But, I cannot see the new handle appearing in window_handles
list after opening a new tab:
>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>>
>>> driver = webdriver.Firefox()
>>> driver.get("http://stackoverflow.com/")
>>> driver.window_handles
[u'{caca92e1-521e-9b4d-9374-00af0ae7d384}']
>>>
>>> # open a new tab
>>> driver.find_element_by_tag_name("body").send_keys(Keys.COMMAND + 't')
>>> driver.window_handles
[u'{caca92e1-521e-9b4d-9374-00af0ae7d384}']
As you can see, window_handles
has the same value, but I see 2 tabs opened in the browser. Is it something I am doing wrong? If yes, how should I obtain the handle of the new tab?
Using:
- selenium 2.44.0 (latest)
- firefox 35.0 (latest)
- python 2.7.6
Note that if I would make a similar thing in Chrome, window_handles
would show 2 handles:
>>> driver = webdriver.Chrome()
>>> driver.get("http://stackoverflow.com/")
>>> driver.execute_script('window.open("about:blank", "_blank");')
>>> driver.window_handles
[u'CDwindow-9458E5DB-D5ED-496C-BEE7-2FA468F3DF42', u'CDwindow-04C0FBBC-C418-465B-B6AF-F72B288B45C6']
解决方案
Only the top level browser window has an HWND. Tabs don't have their own HWNDs. For more clarification refer here.
这篇关于在硒中控制Firefox的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!