游戏门户网站有哪些网站后台怎么做友情链接
游戏门户网站有哪些,网站后台怎么做友情链接,wordpress固定链接改不回来,app登录界面设计图片文章目录一、元素定位操作 API1.1 应用场景1.2 步骤1.3 注意点二、定位一个元素2.1 需求2.2 注意问题三、定位一组元素3.1 需求四、总结4.1 优先用谁#xff1f;#xff08;从上到下选#xff09;4.2 7 种定位写法#xff08;直接复制#xff09;4.3 实战口诀一、元素定位…文章目录一、元素定位操作 API1.1 应用场景1.2 步骤1.3 注意点二、定位一个元素2.1 需求2.2 注意问题三、定位一组元素3.1 需求四、总结4.1 优先用谁从上到下选4.2 7 种定位写法直接复制4.3 实战口诀一、元素定位操作 API1.1 应用场景计算机不像人一样 ”聪明“我们需要通过元素定位来获取元素才能让计算机帮我们 ”操作“ 这个元素。1.2 步骤1、打开 uiautomatorviewer 工具2、打开模拟器或真机3、通过 uiautomatorviewer 工具获取想要进行操作的元素的 Node Detail 信息4、通过元素定位 API 进行定位5、对元素进行相关操作1.3 注意点元素的定位基于当前屏幕范围内展示的可见元素。二、定位一个元素2.1 需求安卓模拟器《设置》界面①通过 id 的形式定位 ”放大镜“ 按钮并点击②通过 class 的形式定位 ”输入框“输入 ”hello“③通过 xpath 的形式定位 ”返回“ 按钮并点击④等待3s关闭app# 1、导包importtimefromappiumimportwebdriver# 这个python类AppiumBy继承自By类用于定义不同的定位策略常量以便在Appium自动化测试中定位元素fromappium.webdriver.common.appiumbyimportAppiumBy# 导入AppiumBy# 2、配置启动参数desired_caps{}# 手机参数desired_caps[platformName]Androiddesired_caps[platformVersion]5.1desired_caps[deviceName]1# 应用参数desired_caps[appPackage]com.android.settingsdesired_caps[appActivity]com.android.settings.Settings# 3、创建APP驱动对象driverwebdriver.Remote(http://localhost:4723/wd/hub,desired_caps)# 4、业务操作# ①通过 id 定位放大镜按钮点击# search_button driver.find_element_by_id(com.android.settings:id/search)# search_button.click()driver.find_element(AppiumBy.ID,com.android.settings:id/search).click()time.sleep(5)# 延迟5秒发送到安卓模拟器# ②通过 class 定位输入框输入hello# driver.find_element_by_class_name(android.widget.EditText).send_keys(hello)driver.find_element(AppiumBy.CLASS_NAME,android.widget.EditText).send_keys(hello)# ③通过 xpath 定位返回按钮点击# driver.find_element_by_xpath(//*[content-desc收起]).click()driver.find_element(AppiumBy.XPATH,//*[content-desc收起]).click()# ④等待3s关闭apptime.sleep(3)# 5、关闭APPdriver.quit()2.2 注意问题selenium.common.exceptions.NoSuchElementException:Message:An element couldnotbe located on the page using the given search parameters.;For documentation on this error,please visit:https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exceptionStacktrace:NoSuchElementError:An element couldnotbe located on the page using the given search parameters.at AndroidUiautomator2Driver.findElOrEls(C:\Users\ggk\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)at processTicksAndRejections(internal/process/task_queues.js:85:5)原因因为用电脑连接安卓模拟器电脑配置太高运行python代码太快导致传输到安卓模拟器还没反映过来。解决方法在代码中加入以下代码time.sleep(5)# 延迟5秒发送到安卓模拟器三、定位一组元素3.1 需求安卓模拟器《设置》界面①通过 id 定位的形式获取所有 resource-id 为 ”com.android.settings:id/title“ 的元素并打印其文字内容。②通过 class_name 的形式获取所有class 为 ”android.widget.TextView“ 的元素并打印其文字内容。③通过 xpath 的形式获取所有包含 ”设“ 的元素并打印其文字内容。# 1、导包importtimefromappiumimportwebdriver# 这个python类AppiumBy继承自By类用于定义不同的定位策略常量以便在Appium自动化测试中定位元素fromappium.webdriver.common.appiumbyimportAppiumBy# 导入AppiumBy# 2、配置启动参数desired_caps{}# 手机参数desired_caps[platformName]Androiddesired_caps[platformVersion]5.1desired_caps[deviceName]1# 应用参数desired_caps[appPackage]com.android.settingsdesired_caps[appActivity]com.android.settings.Settings# 3、创建APP驱动对象driverwebdriver.Remote(http://localhost:4723/wd/hub,desired_caps)# 4、业务操作# - ①通过 id 定位的形式获取所有 resource-id 为 ”com.android.settings:id/title“ 的元素并打印其文字内容。titlesdriver.find_elements(AppiumBy.ID,com.android.settings:id/title)foriintitles:print(i.text)# titles[1].click() # 找到第二个元素蓝牙并点击print(----------------------------)# - ②通过 class_name 的形式获取所有class 为 ”android.widget.TextView“ 的元素并打印其文字内容。foriindriver.find_elements(AppiumBy.CLASS_NAME,android.widget.TextView):print(i.text)print(----------------------------)# - ③通过 xpath 的形式获取所有包含 ”设“ 的元素并打印其文字内容。foriindriver.find_elements(AppiumBy.XPATH,//*[contains(text,设)]):print(i.text)time.sleep(2)# 5、关闭APPdriver.quit()四、总结4.1 优先用谁从上到下选By.IDresource-id→ 最快最稳By.ACCESSIBILITY_IDcontent-desc→移动端特有By.XPath→ 万能、组合条件By.ANDROID_UIAUTOMATOR安卓→ 安卓特有复杂页面强By.IOS_PREDICATEiOS特有坐标→ 最后无奈才用特点移动端页面通常基于原生控件如Android的View、iOS的UIView其结构与Web不同。常用 text 属性进行定位例如xpath_strf//*[text{key_text}]4.2 7 种定位写法直接复制① ID 定位首选Androidresource-idiOSname或accessibility-iddriver.find_element(By.ID,com.tencent.news:id/title_text)② Accessibility IDiOS 巨好用Androidcontent-desciOSaccessibility-iddriver.find_element(AppiumBy.ACCESSIBILITY_ID,搜索)③ XPath最万能、必学多条件组合按文字找父子、兄弟节点定位//*[resource-idxxx]//*[contains(text,关键词)]//类名[resource-idxxxandcontains(text,xxx)]//android.widget.TextView[resource-idxxxandcontains(text,xxx)]④ Class Name控件类型# 一般不单独用页面太多重复要配合列表使用。# 标签名classdriver.find_elements(By.CLASS_NAME,android.widget.TextView)⑤ Android UIAutomator安卓专属很强driver.find_element_by_android_uiautomator(new UiSelector().resourceId(xxx).textContains(亚冠))⑥ iOS Class ChainiOS 专属替代 XPath**/XCUIElementTypeStaticText[name CONTAINS 登录]⑦ 坐标定位不推荐driver.tap([(x,y)])4.3 实战口诀有 ID 用 ID没 ID 用文本多条件用 and不乱用坐标//android.widget.TextView[resource-idxxx and contains(text,xxx)]