Selenium自动化测试及框架(selenium+python) - 第一个简单脚本

本文介绍了如何创建一个简单的Python项目,利用Selenium WebDriver进行自动化测试。首先,新建Python文件并输入代码,接着配置Firefox浏览器的driver。虽然在运行Chrome或IE driver时遇到了问题,但该示例展示了Selenium的基础应用。通过加载配置文件,可以进一步扩展其功能。
摘要由CSDN通过智能技术生成

PART 2 : create a siimple python project to run selenium webdriver

1. create a new python file under the project.  在项目名称上右键新建python file,然后取一个file name.

           

2. copy the code into the python file

# -*- coding:utf-8 -*-
from selenium import webdriver
# create a new Firefox session
driver = webdriver.Firefox()
driver.implicitly_wait(10)  # 设置超时时间
driver.maximize_window()  # 窗口最大化显示
#  navigate to the application home page
driver.get("http://www.baidu.com/")
# get the search textbox
search_field = driver.find_element_by_id("kw")  # 找到输入框
search_field.clear()  # 清空当前输入内容
# enter search keyword and submit
search_field.send_keys("Selenium2")  # 重新这是搜索关键字
search_field.submit()  # 提交进行搜索
# get all the anchor elements which have product names displayed
#  currently on result page using fi
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值