通过远程URL连接而不是localhost运行Appium脚本
我有一个 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 :
Is my approach right or not applicable?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要
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 usewebdriver.Remote("http://10.237.93.136:4723/wd/hub", dc)
Also make sure the ports are open and server is accessible.