一。环境部署

1.selenium安装 

pip3 install selenium

1.安装浏览器驱动

WebDriver 需要通过浏览器驱动来与浏览器交互,以下列出几种常用的浏览器驱动下载地址:

Chrome:

http://chromedriver.storage.googleapis.com/index.html

Firefox:
https://github.com/mozilla/geckodriver/releases

Edge:
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver

Safari:
https://webkit.org/blog/6900/webdriver-support-in-safari-10

使用不同的浏览器,需要下载对应版本驱动,并且确保驱动文件如chromedriver.exe放到你的系统环境PATH中,这里我将它放到python安装目录下。D:\Python36\chromedriver.exe

selenium思维导图详细使用介绍:

二。元素定位:

selenium自动化测试python

 1 <!DOCTYPE html>
 2 <html lang="zh-CN">
 3 <body>
 4     <h1 class="head_title">你好,<span id="world">世界!</span></h1>
 5     <a href="https://www.kancloud.cn/@guanfuchang" target="_blank">我的看云首页</a>
 6     <br/>
 7     <br/>
 8     <div id="login_form" class="login">
 9         用户名:<input name="username" class="ptqa user_name" placeholder="用户名" value="Milton" required/>
10         密码:<input type="text" name="password" class="ptqa pwd" placeholder="密码" value="ptqa" required/>
11         地区:
12         <select class="city">
13             <option value="gz">广州</option>
14             <option value="fs">佛山</option>
15             <option value="mm">茂名</option>
16             <option value="hb">襄樊</option>
17         </select>
18 
19         <br>
20         <br>
21         <button>提交</button>
22         <br>
23 
24     </div>
25 </body>
26 </html>
环境准备

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2018-03-18
  • 2021-07-10
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
猜你喜欢
  • 2021-12-13
  • 2021-04-23
  • 2021-05-18
  • 2020-04-27
  • 2021-07-27
  • 2021-07-20
相关资源
相似解决方案