Python+Selenium操作之浏览器操作

1.浏览器的后退操作(back)

# coding=utf-8

import time

from selenium import webdriver

driver = webdriver.Firefox()

driver.maximize_window()

time.sleep(2)

driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/a[1]').click()

time.sleep(2)

print driver.title

'''

执行后退操作

'''

driver.back()

print driver.title

time.sleep(2)

2.浏览器的前进操作(forward)

# coding=utf-8

import time

from selenium import webdriver

driver = webdriver.Firefox()

driver.maximize_window()

time.sleep(2)

driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/a[1]').click()

time.sleep(2)

print u'标题1:'+driver.title

'''

执行后退操作

'''

driver.back()

print u'标题2:'+driver.title

time.sleep(2)

'''

执行前进操作

'''

driver.forward()

print u'标题3:'+driver.title

3.浏览器刷新操作(refresh)

# coding=utf-8

import time

from selenium import webdriver

driver = webdriver.Firefox()

driver.maximize_window()

time.sleep(2)

driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/a[1]').click()

time.sleep(2)

title1=driver.title

print u'标题1:'+title1

'''

执行后退操作

'''

driver.refresh()

title2=driver.title

print u'标题2:'+title2

if title1==title2:

print u'刷新成功'

else:

print u'刷新命令错误'

  • 发表于:
  • 原文链接:http://kuaibao.qq.com/s/20180125G0498500?refer=cp_1026

同媒体快讯

扫码关注云+社区