0

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

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

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

有没有办法解决这个问题?

我的 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
4

2 回答 2

0

您可以添加隐式等待,让驱动程序在每一步都等待元素。隐式等待的默认时间为 0

driver.implicitly_wait(10) #timeout in seconds
于 2019-01-15T06:56:06.790 回答
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 中的 sleep 方法使用 time

time.sleep(5)
于 2019-01-15T06:20:31.770 回答