【问题标题】:Running Appium script through remote url connection instead of localhost通过远程 url 连接而不是 localhost 运行 Appium 脚本
【发布时间】:2022-06-30 21:15:57
【问题描述】:

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

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


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())

但它会导致以下错误:

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

谢谢

【问题讨论】:

    标签: python android selenium-webdriver appium remote-access


    【解决方案1】:

    你不需要RemoteConnection方法,localhost也是一个有效的url/ip地址,就像远程ip一样,所以只需使用webdriver.Remote("http://10.237.93.136:4723/wd/hub", dc)

    还要确保端口已打开且服务器可访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      相关资源
      最近更新 更多