如何使用远程驱动程序在Windows上运行IE和chrome浏览器来解决“超时”问题

时间:2019-01-14 20:31:10

标签: python selenium selenium-server

我需要在IE和Chrome浏览器中的远程Windows上运行一些测试。 但是我在主机上收到超时错误,并且 Exit value: -1073741819在远程上。 我有最新版本的驱动程序和服务器。我在64 Windows上使用32位Selenium服务器(建议)

我已经将所有内容添加到PATH中,但是如果我通过cmd运行chromedriver,我什么也没得到。我不知道为什么(在管理模式下也是如此)

如果我通过Pycharm在Windows上本地运行测试,即使我使用localhost:4444作为远程URL通过服务器运行它也没有任何问题 问题仅在于远程运行。

有什么解决方案可以解决该问题吗?

我的Python代码中有

desired_capabilities: DesiredCapabilities = {
            'chrome': DesiredCapabilities.CHROME,
            'firefox': DesiredCapabilities.FIREFOX,
            'IE': DesiredCapabilities.INTERNETEXPLORER,}.get(browser, DesiredCapabilities.CHROME)

driver = webdriver.Remote(command_executor=remote_url, desired_capabilities=desired_capabilities)

我使用命令运行:

pytest tests/test.py --remote_url Remote_IP:4444/wd/hub --browser IE

Selenium服务器可以在Windows终端中看到我的请求并显示:

12:53:00.975 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browserName": "internet explorer",
  "platform": "WINDOWS",
  "version": ""
}
12:53:00.975 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.ie.InternetExplorerDriverService)
12:53:21.022 ERROR [OsProcess.checkForError] - org.apache.commons.exec.ExecuteException: Process exited with an error: -1073741819 (Exit value: -1073741819)

也在我的本地终端中,我看到了错误:

E selenium.common.exceptions.WebDriverException: Message: Timed out waiting for driver server to start.
E Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
E System info: host: 'HOST NAME', ip: 'REMOTE IP', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
E Driver info: driver.version: unknown
E Stacktrace:
E at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable (DriverService.java:202)
E at org.openqa.selenium.remote.service.DriverService.start (DriverService.java:188)
E at org.openqa.selenium.grid.session.remote.ServicedSession$Factory.apply (ServicedSession.java:155)
E at org.openqa.selenium.remote.server.ActiveSessionFactory.lambda$apply$12 (ActiveSessionFactory.java:180)
E at java.util.stream.ReferencePipeline$3$1.accept (None:-1)
E at java.util.stream.ReferencePipeline$11$1.accept (None:-1)
E at java.util.stream.ReferencePipeline$2$1.accept (None:-1)
E at java.util.Spliterators$ArraySpliterator.tryAdvance (None:-1)
E at java.util.stream.ReferencePipeline.forEachWithCancel (None:-1)
E at java.util.stream.AbstractPipeline.copyIntoWithCancel (None:-1)
E at java.util.stream.AbstractPipeline.copyInto (None:-1)
E at java.util.stream.AbstractPipeline.wrapAndCopyInto (None:-1)
E at java.util.stream.FindOps$FindOp.evaluateSequential (None:-1)
E at java.util.stream.AbstractPipeline.evaluate (None:-1)
E at java.util.stream.ReferencePipeline.findFirst (None:-1)
E at org.openqa.selenium.remote.server.ActiveSessionFactory.apply (ActiveSessionFactory.java:183)
E at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$2 (NewSessionPipeline.java:66)
E at java.util.stream.ReferencePipeline$3$1.accept (None:-1)
E at java.util.stream.ReferencePipeline$2$1.accept (None:-1)
E at java.util.Collections$2.tryAdvance (None:-1)
E at java.util.stream.ReferencePipeline.forEachWithCancel (None:-1)
E at java.util.stream.AbstractPipeline.copyIntoWithCancel (None:-1)
E at java.util.stream.AbstractPipeline.copyInto (None:-1)
E at java.util.stream.AbstractPipeline.wrapAndCopyInto (None:-1)
E at java.util.stream.FindOps$FindOp.evaluateSequential (None:-1)
E at java.util.stream.AbstractPipeline.evaluate (None:-1)
E at java.util.stream.ReferencePipeline.findFirst (None:-1)
E at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$3 (NewSessionPipeline.java:69)
E at java.util.stream.ReferencePipeline$3$1.accept (None:-1)
E at java.util.stream.ReferencePipeline$3$1.accept (None:-1)
E at java.util.stream.ReferencePipeline$3$1.accept (None:-1)
E at java.util.stream.DistinctOps$1$2.accept (None:-1)
E at java.util.stream.ReferencePipeline$2$1.accept (None:-1)
E at java.util.stream.ReferencePipeline$3$1.accept (None:-1)
E at java.util.stream.ReferencePipeline$2$1.accept (None:-1)
E at java.util.stream.Streams$StreamBuilderImpl.tryAdvance (None:-1)
E at java.util.stream.Streams$ConcatSpliterator.tryAdvance (None:-1)
E at java.util.stream.ReferencePipeline.forEachWithCancel (None:-1)
E at java.util.stream.AbstractPipeline.copyIntoWithCancel (None:-1)
E at java.util.stream.AbstractPipeline.copyInto (None:-1)
E at java.util.stream.AbstractPipeline.wrapAndCopyInto (None:-1)
E at java.util.stream.FindOps$FindOp.evaluateSequential (None:-1)
E at java.util.stream.AbstractPipeline.evaluate (None:-1)
E at java.util.stream.ReferencePipeline.findFirst (None:-1)
E at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession (NewSessionPipeline.java:72)
E at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute (BeginSession.java:65)
E at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0 (WebDriverServlet.java:235)
E at java.util.concurrent.Executors$RunnableAdapter.call (None:-1)
E at java.util.concurrent.FutureTask.run (None:-1)
E at java.util.concurrent.ThreadPoolExecutor.runWorker (None:-1)
E at java.util.concurrent.ThreadPoolExecutor$Worker.run (None:-1)
E at java.lang.Thread.run (None:-1) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py:242: WebDriverException

我也得到日志(REMOTE_IP是远程Windows地址):

remote_connection.py 390 DEBUG POST REMOTE_IP:4444/wd/hub/session {"capabilities": {
"firstMatch": [{}], "alwaysMatch": {"browserName": "internet explorer", "platformName": "windows"}}, 
"desiredCapabilities": 
    {"browserName": "internet explorer", 
     "version": "", 
     "platform": "WINDOWS"}}

connectionpool.py 208 DEBUG Starting new HTTP connection (1): REMOTE_IP
connectionpool.py 396 DEBUG http://REMOTE_IP:4444 "POST /wd/hub/session HTTP/1.1" 500 14404
remote_connection.py 442 DEBUG Finished Request

2 个答案:

答案 0 :(得分:0)

您可以使用显式等待来避免超时,它会等待10秒钟直到发现是否超时将引发超时错误,并且您可以将时间增加到30秒任意多

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
finally:
    driver.quit()

如果这不起作用,则可以使用Thread using time的睡眠方法

time.sleep(5)

答案 1 :(得分:0)

您可以添加隐式等待,以使驱动程序在每个步骤中等待元素。 隐式等待的默认时间为0

id