selenium+python 浏览器标签页跳转 switch_to_window
2013-08-29 18:15
459 查看
浏览器页面跳转方法记录:
如果打开多个浏览器句柄和标签页的对应关系:
标签页顺序(按照打开顺序):1 2 3 4 5
对应的句柄 :0 4 3 2 1
依次类推
from selenium import webdriver import time browser = webdriver.Chrome() first_url='http://www.baidu.com' browser.find_element_by_xpath('//div/div/div/ul/li[1]/strong/a').click() browser.switch_to_window(browser.window_handles[0]) browser.title #第一个页面 browser.switch_to_window(browser.window_handles[1]) browser.title #最后一个页面 browser.quit()
如果打开多个浏览器句柄和标签页的对应关系:
标签页顺序(按照打开顺序):1 2 3 4 5
对应的句柄 :0 4 3 2 1
依次类推
相关文章推荐
- Selenium2(Webdriver)+Python处理浏览器多标签方法二则
- Selenium - IWebDriver.SwitchTo() frame 和 Window 的用法
- 使用selenium+python;在页面A点击一个按钮跳转到页面B,页面A没有关闭,浏览器打开了一个B,切换窗口定位页面B的元素
- Selenium - IWebDriver.SwitchTo() frame 和 Window 的用法
- 【Python】selenium调用IE11浏览器,报错“找不到元素”NoSuchWindowException: Message:Unable to find element on closed window
- python+selenium 使用switch_to_alert 出现的怪异常
- 转python+selenium 使用switch_to_alert 出现的怪异常
- js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题
- Selenium - IWebDriver.SwitchTo() frame 和 Window 的用法
- python+selenium 使用switch_to_alert 出现的怪异常
- 8、Selenium + Python 实现 UI 自动化测试-操作浏览器标签
- python selenium 3.4 错误解决 Message: 'geckodriver' executable needs to be in PATH.
- python中selenium结合chrome操作浏览器,并解决chrome与chromedriver版本不匹配问题
- python3.5+django1.10:selenium.common.exceptions.WebDriverException->moveto did not match a known com
- python selenium 获取标签的属性值、内容、状态方法
- python爬虫:使用Selenium模拟浏览器行为
- 【selenium】python+selenium+unittest,关于每次执行完一个测试用例都关闭浏览器等时间较长的问题之解决方案
- 轻松自动化---selenium-webdriver(python) (二)---打印URL,设置浏览器固定宽前进后退等
- 将鼠标放在A标签上时浏览器左下角会显示跳转后界面地址,如何隐藏
- 一些窗口API函数,比如SetForegroundWindow,SwitchToThisWindow