51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1711|回复: 0

window下python3+selenium3安装

[复制链接]
  • TA的每日心情
    无聊
    昨天 09:21
  • 签到天数: 398 天

    连续签到: 4 天

    [LV.9]测试副司令

    发表于 2018-12-18 15:15:56 | 显示全部楼层 |阅读模式
    一、目录
    windows下python3.6.5下载安装
    windows下selenium3下载安装
    windows下pycharm下载安装 (python代码编辑器)
    windows下chrome下载安装
    drivers下载

    二、下载链接准备
    python官方下载链接: https://www.python.org/downloads/  
    pycharm官方下载链接:http://www.jetbrains.com/pycharm/download/#section=windows(这里选择Professional版,先下载之后破解使用)
    chrome浏览器下载链接: https://chrome.en.softonic.com/

    三、软件安装
    1)python安装
    下载好python之后,点击exe文件,选择安装目录,成功之后,windows+R 输入cmd,弹出命令行窗口,输入python, 查看python版本
    Microsoft Windows [版本 10.0.16299.371]
    (c) 2017 Microsoft Corporation。保留所有权利。
    C:\Users\FE>python
    Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    2.selenium安装
    安装好python3之后,默认就有pip, 使用pip安装selenium
    命令行输入如下命令:
    pip install selenium

    三、Chrome安装
    四、Drivers下载

    Chrome:

    Edge:

    Firefox:

    Safari:

    注意:Drivers的版本要下载与浏览器相对应的版本,不然会报错
    chrome浏览器可以参照链接:http://npm.taobao.org/mirrors/chromedriver/
    将下载好的driver放至python根目录下

    五、安装pycharm
    破解方法可参考链接:https://blog.csdn.net/u014044812/article/details/78727496

    六、第一个webdriver示例

    1. from selenium import webdriver
    2. from <span style="box-sizing: inherit;">selenium.common.exceptions</span> import TimeoutException
    3. from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
    4. from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
    5. # Create a new instance of the Firefox driver
    6. driver = webdriver.Chrome()
    7. # go to the google home page
    8. driv<span style="color: rgb(47, 79, 79);">er.get("</span><span style="color: rgb(47, 79, 79); box-sizing: inherit;">http://www.google.com</span><span style="color: rgb(47, 79, 79);">")</span>
    9. # the page is ajaxy so the title is originally this:
    10. print driver.title
    11. # find the element that's name attribute is q (the google search box)
    12. inputElement = driver.find_element_by_name("q")
    13. # type in the search
    14. inputElement.send_keys("cheese!")
    15. # submit the form (although google automatically searches now without submitting)
    16. inputElement.submit()
    17. try:
    18. # we have to wait for the page to refresh, the last thing that seems to be updated is the title
    19. WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))
    20. # You should see "cheese! - Google Search"
    21. print driver.title
    22. finally:
    23. driver.quit()
    复制代码



    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-4-19 06:42 , Processed in 0.068082 second(s), 24 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表