码迷,mamicode.com
首页 > 编程语言 > 详细

Python+Selenium浏览器后退前进操作+获取当前页面title+获取当前页面url

时间:2017-10-20 13:36:31      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:sele   cli   str   selenium   title   xpath   implicit   current   url   

#coding=utf-8  
  
from selenium import webdriver  
import time 
  
driver = webdriver.Chrome()  
driver.maximize_window()  
driver.implicitly_wait(6)  
  
driver.get("https://www.baidu.com")  
driver.find_element_by_id("kw").send_keys("Selenium")
driver.find_element_by_id("su").click()
time.sleep(3)

driver.back()
time.sleep(3)

driver.forward()
time.sleep(3)

ele_string = driver.find_element_by_xpath("//*[@id=‘1‘]/h3/a/em").text  
if (ele_string == "Selenium"):  
	print u"测试成功,结果和预期结果匹配!" 
	
print(driver.capabilities[‘version‘]) 

driver.find_element_by_xpath("//*[@id=‘s_tab‘]/a[text()=‘新闻‘]").click() # 在搜索结果页面点击新闻类别  

time.sleep(1)  

print (driver.current_url)  # current_url 方法可以得到当前页面的URL  
print (driver.title)  # title方法可以获取当前页面的标题显示的字段  

driver.quit()

  

Python+Selenium浏览器后退前进操作+获取当前页面title+获取当前页面url

标签:sele   cli   str   selenium   title   xpath   implicit   current   url   

原文地址:http://www.cnblogs.com/xiaomogu110/p/7698552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!