通过远程URL连接而不是localhost运行Appium脚本

发布于 2025-01-18 15:56:35 字数 1240 浏览 3 评论 0原文

我有一个 Windows 虚拟机,其中安装了 Appium,并且有一个物理设备连接到它。

在虚拟机中,下面的代码工作正常,可以从连接的移动设备获取日期:


from appium import webdriver
from selenium.webdriver.remote.remote_connection import RemoteConnection

dc={
"platformName": "Android",
"appium:deviceName": "Android Emulator",
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", dc)
print(driver.get_device_time())

如果我想通过该虚拟机在我的计算机中运行相同的代码,根据该参考:https://www.programcreek.com/python/example/100038/appium.webdriver.Remote

我应该用ip地址替换localhost,所以代码应该如下

from appium import webdriver
from selenium.webdriver.remote.remote_connection import RemoteConnection

dc={
"platformName": "Android",
"appium:deviceName": "Android Emulator",
}
print(dc)
# Creating the Driver by passing Desired Capabilities.
driver = webdriver.Remote(RemoteConnection("http://10.237.93.136:4723/wd/hub",resolve_ip=False),dc)

print(driver.get_device_time())

:导致以下错误:

在此处输入图像描述

我的方法正确还是不适用?

谢谢

I have a windows virtual machine in which Appium installed and there's a physical device connected to it.

In the virtual machine the code below is working fine which get the date from the mobile connected :


from appium import webdriver
from selenium.webdriver.remote.remote_connection import RemoteConnection

dc={
"platformName": "Android",
"appium:deviceName": "Android Emulator",
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", dc)
print(driver.get_device_time())

If I want to run the same code in my machine through that virtual machine , according to that reference : https://www.programcreek.com/python/example/100038/appium.webdriver.Remote

I should be replacing the localhost with the ip address , so the code should be as the following :

from appium import webdriver
from selenium.webdriver.remote.remote_connection import RemoteConnection

dc={
"platformName": "Android",
"appium:deviceName": "Android Emulator",
}
print(dc)
# Creating the Driver by passing Desired Capabilities.
driver = webdriver.Remote(RemoteConnection("http://10.237.93.136:4723/wd/hub",resolve_ip=False),dc)

print(driver.get_device_time())

But it's causes the following error :

enter image description here

Is my approach right or not applicable?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林散布 2025-01-25 15:56:35

您不需要remoteConnection方法,localhost也是一个有效的URL/IP地址,就像远程IP一样,只需使用webdriver.remote(“ http://10.237.93.136:” 4723/WD/HUB“,DC)

还确保端口是打开的,并且服务器可访问。

You don't need the RemoteConnection method, the localhost is also a valid url/ip address just like the remote ip so just use webdriver.Remote("http://10.237.93.136:4723/wd/hub", dc)

Also make sure the ports are open and server is accessible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文