51Testing软件测试论坛

标题: window下python3+selenium3安装 [打印本页]

作者: 测试积点老人    时间: 2018-12-18 15:15
标题: window下python3+selenium3安装
一、目录
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:

https://sites.google.com/a/chromium.org/chromedriver/downloads

Edge:

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

Firefox:

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

Safari:

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

注意: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()
复制代码








欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2