当前位置: 首页 > 工具软件 > Forward DL > 使用案例 >

selenium之 浏览器导航栏的三个按钮(back、forward、refresh)

彭畅
2023-12-01

一、操作代码

# -*- coding: utf-8 -*-

"""
@author: lucas
@Function:
@file: backAndForwardAndRefresh.py
@time: 2021/8/23 11:43 上午
"""
import unittest

from selenium import webdriver
from time import sleep


class BackAndForwardAndRefresh(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()

    def test_window_operate(self):
        driver = self.driver

        driver.maximize_window()
        driver.get('http://www.baidu.com')
        print 'base_url: ', driver.current_url

        driver.find_element_by_id('kw').send_keys(u'进击的雷神')
        driver.find_element_by_id('su').click()
        sleep(2)
        print 'after search: ', driver.current_url
        # back
        driver.back()
        print 'back to: ', driver.current_url
        # forward
        driver.forward()
        print 'forward to: ', driver.cur
 类似资料: