遇到的问题:
python 3.5 +selenium3.0 环境下在
firefox执行示例脚本时提示;firefox(27 43 50)3个版本都会提示“
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:\Program Files (x86)\Mozilla Firefox\firefox.exe”
-------------------------------------
原因及解决方法:
--------------------------------------
早在2013年的时候,Selenium官方宣布,Selenium新的版本会在圣诞节的时候发布。但是,他们并没有说哪一个圣诞节发布。
转眼的三年过去了,目前已经发布到Selenium3.0 beta4版本,这将会是Selenium3.0正式版本前的最后一个
测试版本。
尽管我对Selenium3.0比较失望(本以为它会集成
移动端的
自动化测试)。但是,它还是做了一些变动。
Selenium3.0的变化
最大的变化应该是去掉了Selenium RC 了,这是必然的结果。Selenium RC 是Selenium1.0的产物,Selenium2.0以WebDriver为主,经过这么多年有发展,Selenium RC已经很少有人在用了。Selenium3.0版本去掉是个必然的结果。
You’ll need to be running Java 8 to use the Java pieces of Selenium. This is the oldest version of Java officially supported by
Oracle, so hopefully you’re using it already!
Selenium3.0只支持Java8版本以上,所以,如果你是用Java+Selenium开发自动化测试,那么Java JDK需要升级到Java8了,对于其它编程来说可以忽略这点,除非你要使用Selenium Grid。
Support for Firefox is via Mozilla’s geckodriver.
Selenium3.0中的Firefox驱动独立了,在Selenium3.0之前,只要在不同编程语言下安装好Selenium就可以驱动Firefox浏览器运行自动化测试脚本。这是因为不同语言下的Selenium库中移动包含了Firefox浏览驱动。
然而,现在Firefox浏览器驱动与Selenium库分离,单独提供下载。
下载地址:https://github.com/mozilla/geckodriver/releases
不过,geckodriver驱动要求Friefox浏览器必须48版本以上。
Support for Safari is provided on macOS (Sierra or later) via Apple’s own safaridriver.
Safari是
苹果公司的
浏览器,然后,它也早就实现了多平台的支持,同样可以在
Windows下运行,然而,它的驱动比较有意思,是集成到Selenium
Server中的。也就是说你想让自动化测试脚本在Safari浏览器上运行,必须使用Selenium Server。
Support for Edge is provided by MS through their webdriver server.
Only versions 9 or above of IE are supported. Earlier versions may work, but are no longer supported as MS no longer supports them.
如何使用浏览器驱动
读者可以单独创建一个目录,如:D:/drivers/ ,把不同浏览器的驱动都放到该目录。geckodriver.exe(Firefox)、chromedriver.exe(Chrome)、MicrosoftWebDriver.exe(Edge)、IEDriverServer.exe(IE)、operadriver.exe(Opera)等。
然后,将D:/drivers/添加到系统环境变最path下面即可。
Python安装Selenium3.0
通过pip安装,3.0.0b3为当前最新版本。
>pip install selenium==3.0.0b3
Selenium3.0的API没有任何改变,跑个简单的例子验证一下。
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Selenium2")
driver.find_element_by_id("su").click()
driver.quit()
===========================================================
来自网络:http://www.tools138.com/create/article/20161006/020013212.html