Python自动化测试-Selenium

Selenium自动化测试 – 启动浏览器

第一个selenium就。。。

先show代码:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.oxcoder.com")
assert "oxcoder".decode('utf-8') in driver.title
print driver.title
driver.close()

这只是一段使用selenium操作firefox的代码,最核心一句就是webdriver.Firefox()
然而,轻松写完却无法启动,出现如下问题:

问题No.1 - 找不到可执行文件geckodriver

Traceback (most recent call last):
  File "/Users/sure/Python/helloSelenium.py", line 3, in <module>
    driver = webdriver.Firefox()
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x10861a490>> ignored
[Finished in 0.2s with exit code 1]
[shell_cmd: python -u "/Users/sure/Python/helloSelenium.py"]
[dir: /Users/sure/Python]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

解决方案:
- 下载对应的webdriver:
- Firefox - geckodriver
- chrome - chromedriver 或使用~> pip/brew install chromedriver

  • python目录下/usr/local/bin

问题No.2 - 无法连接

还以为就这样解决了,谁知道。。。

Traceback (most recent call last):
  File "/Users/sure/Python/helloSelenium.py", line 3, in <module>
    driver = webdriver.Firefox()
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 102, in start
    raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver

[Finished in 30.5s with exit code 1]
[shell_cmd: python -u "/Users/sure/Python/helloSelenium.py"]
[dir: /Users/sure/Python]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

解决方案:
- 据说这是Selenium的问题参考github
- 【求教】有人知道怎么破吗???


此文仅适用于Mac OSX

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值