import time标签:浏览器,selenium,driver,12.1,初识,sleep,time,print From: https://www.cnblogs.com/zhh0125/p/16666938.html
# 通过selenium 操作浏览器,必须有一个浏览器的驱动对象
from selenium import webdriver
# 2.配置不同的驱动对象
# 3.建议下载好放在python\scripts目录下
driver=webdriver.Chrome()
# driver=webdriver.Firefox()
driver.get('https://www.baidu.com')
driver.maximize_window() #最大化浏览器窗口
time.sleep(3)
input_obj=driver.find_element_by_id('kw')
input_obj.send_keys('断浪狂刀忆少年')
time.sleep(5)
# input_obj.clear()#清空
#
driver.find_element_by_id('su').click()#点击框的id生成地址是su
time.sleep(5)
print(driver.title)#获取当前页面的标题
print('--------')
print(driver.page_source)#获取当前页面的内置内容
print(driver.get_window_size())#获取当前浏览器窗口的大小
time.sleep(2)
driver.refresh()#刷新
time.sleep(2)
driver.back()#后退
time.sleep(2)
driver.forward()#前进
time.sleep(1)
# print(driver.get_cookies())#获取cookies
# print(driver.current_url)#获取当前窗口的url
# print('!!!!!!')
# print(driver.current_window_handle)#获取当前串口的对象
#
# driver.save_screenshot('截图.png')#屏幕截图,只直接png格式
# time.sleep(3)
# driver.execute_script("alret('你好呀!!!‘)")
# time.sleep(6)
#
# driver.close()#关闭当前窗口