Selenium Python所需的功能无法创建新的驱动程序实例

时间:2016-05-10 14:51:21

标签: python-2.7 selenium selenium-webdriver

我正在尝试在我们的64位计算机,Windows 2008上使用Selenium Python中的Desired Capabilities for IE,因为IEDriverServer.exe在我使用时会在测试中途停止崩溃:

cls.driver = webdriver.Ie(Globals.IEdriver_path)

我想尝试Desired Capabilities,看看它是否正常运行。

我的设置中有以下内容:

    class BaseTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):

    desired_caps = {}
    desired_caps['platform'] = 'WINDOWS'
    desired_caps['browserName'] = 'INTERNETEXPLORER'
    #cls.driver = webdriver.Remote('http://192.168.1.103:4444/wd/hub', desired_caps)
    cls.driver = webdriver.Remote('http://127.0.0.1:4444/wd/hub', desired_caps)
    cls.driver = webdriver.Ie(Globals.IEdriver_path)
    cls.driver.get(Globals.URL)
    cls.login_page = login.LoginPage(cls.driver)

我按如下方式运行Selenium Server jar文件:

    java -Dwebdriver.ie.driver="C:\\IEDriverServer.exe" -jar
selenium-server-standalone-2.53.0.jar

当我运行Selenium Python测试时,我收到以下错误:

  WebDriverException: Message: The best matching driver provider org.openqa.selenium.ie.InternetExplorerDriver can't create a new driver instance for Capabilities [{browserName=INTERNETEXPLORER, platform=WINDOWS}]
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'JUSTIN-PC', ip: '192.168.1.164', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_45'
Driver info: driver.version: unknown
Stacktrace:
    at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance (DefaultDriverFactory.java:62)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:222)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:1)
    at java.util.concurrent.FutureTask.run (None:-1)
    at org.openqa.selenium.remote.server.DefaultSession$1.run (DefaultSession.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (None:-1)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (None:-1)
    at java.lang.Thread.run (None:-1)

如果我使用:

cls.driver = webdriver.Remote('http://192.168.1.103:4444/wd/hub', desired_caps)

然后我会收到以下错误:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

我应该如何在Selenium Python中设置所需的功能?

谢谢Riaz

1 个答案:

答案 0 :(得分:1)

以下是使用Internet Explorer启动远程会话的示例:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capabilities = DesiredCapabilities.INTERNETEXPLORER
capabilities.update({'logLevel' : 'ERROR'})
remote_server = "http://127.0.0.1:4444/wd/hub"

driver = webdriver.Remote(remote_server, capabilities)
driver.get('http://stackoverflow.com/')