代码详情如下:
import time
from appium import webdriver
import pytest
class TestDw:
def setup(self):
desired_caps = {}
# 系统类型
desired_caps['platformName'] = 'Android'
# 模拟器地址
desired_caps['deviceName'] = '127.0.0.1:7555'
# 测试包名
desired_caps['appPackage'] = 'com.xueqiu.android'
# 首次进入的页面
desired_caps['appActivity'] = '.common.MainActivity'
# 设置支持输入为中文
desired_caps['unicodeKeyBoard'] = 'true'
desired_caps['resetKeyBoard'] = 'true'
# 初始设置,缓存是否清理设置
# desired_caps['noReset'] = 'true'
# # 重启app设置
# desired_caps['dontStopAppOnReset'] = 'true'
# 跳过安装设置
desired_caps['skipDeviceInitialization'] = 'true'
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
self.driver.implicitly_wait(15)
def teardown(self):
time.sleep(20)
self.driver.quit()
def test_dw(self):
self.driver.find_element_by_id("com.xueqiu.android:id/tv_search").click()
self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("阿里巴巴")
self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/stockName' and @text='阿里巴巴']")
price = float(self.driver.find_element_by_id("com.xueqiu.android:id/current_price").text)
assert price > 200
报错信息如下:selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
这个代码都跟录播课里的一样,但是一直报错,卡了我一天了 = =!