Python+Appium尋找藍牙/wifi匹配

前言:

此篇是介紹怎么去尋找藍牙,進行匹配。主要2個問題點:

1.在不同環境下,搜索到的藍牙數量有變

2.在不同環境下,搜索到的藍牙排序會變

簡單思路:

將搜索出來的藍牙名字添加到一個list去,然后在去匹配list里是否有你要匹配的藍牙,找到了就點擊,沒找到,又進行下一次尋找,知道找到為止

簡單代碼:

#coding:utf-8
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import time
bluetoothName="iPhone"
desired_caps = {'platformName': 'Android','deviceName': '9a762346','platformVersion': '6.0.1','noReset': True,'appPackage': 'com.android.settings','appActivity': '.Settings'}
driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
size = driver.get_window_size()
print ('屏幕的分辨率: %s'% size) 
print ('啟動成功')
WebDriverWait(driver,30,1).until(lambda x:x.find_element_by_xpath('//*[@text="藍牙"]')).click()
print('正在搜索藍牙設備,請等待30s')  #因為不清楚藍牙停止搜索的機制是什么,這里就讓強制等待30s
time.sleep(10)
print('已經搜索10s,還剩20s')
time.sleep(10)
print('已經搜索20s,還剩10s')
time.sleep(10)
print('已經搜索30s,還剩0s')
print('搜索完畢')
a=driver.find_elements_by_id('android:id/title')
b=[]  # 創建一個空的list,用于后面存放打印的文本
for j in range(1,11):  #控制滑動次數for i in range(10):  #這個10是a的數量。當然也可以直接 len(a)
        b.append(a[i].text)x1=size['width'] * 0.5y1=size['height'] * 0.75y2=size['height'] * 0.25driver.swipe(x1, y1, x1, y2, 120)   #這個 1 20  滑動時間建議不要太多,很容滑過去time.sleep(2)  # 這個sleep必須要有,沒有的話就會導致滑太快if "iPhone" in b:WebDriverWait(driver,60,1).until(lambda x:x.find_element_by_xpath('//*[@text="iPhone"]')).click()print(''+str(j)+'次滑動設備找到藍牙')break   #找到了就跳出循環else:print(''+str(j)+'次滑動設備藍牙未找到,2s后進行下一次尋找')try:WebDriverWait(driver,20,1).until(lambda x:x.find_element_by_xpath('//*[@text="配對"]')).click()print('點擊 配對完成')
except:print('配對按鈕沒找到(20s),設備藍牙未找到')

?同理? WiFi也可以用同樣的方法去尋找

#coding:utf-8
import unittest
from common.base import BaseApp
from appium import webdriver
from common.logger import Log
from selenium.webdriver.support.ui import WebDriverWait
import timedesired_caps = {'platformName': 'Android','deviceName': '9a762346','platformVersion': '6.0.1','noReset': True,'unicodeKeyboard': True,'resetKeyboard': True,'appPackage': 'com.android.settings','appActivity': '.Settings'}u'''測試wifi連接'''
class Test(unittest.TestCase):@classmethoddef setUpClass(cls):cls.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)cls.base=BaseApp(cls.driver)cls.log=Log()def setUp(self):passdef testName(self):self.log.info('設備啟動成功')self.size = self.driver.get_window_size()WebDriverWait(self.driver,30,1).until(lambda x:x.find_element_by_xpath('//*[@text="WLAN"]')).click()WebDriverWait(self.driver,30,1).until(lambda x:x.find_element_by_xpath('//*[@text="刷新"]')).click()self.log.info('點擊刷新成功')time.sleep(15)self.log.info('15s搜索完畢')a=self.driver.find_elements_by_id('android:id/title')b=[]  for j in range(1,31):  for i in range(len(a)):try:b.append(a[i].text)except:self.log.info('添加文本時發生錯誤')  if "iPhone羅" in b:WebDriverWait(self.driver,60,1).until(lambda x:x.find_element_by_xpath('//*[@text="iPhone羅"]')).click()self.log.info(''+str(j)+'次滑動設備找到wifi')self.log.info(b)break   else:x1=self.size['width'] * 0.5y1=self.size['height'] * 0.75y2=self.size['height'] * 0.50self.driver.swipe(x1, y1, x1, y2, 200)   self.log.info(list(set(b)))time.sleep(2) self.log.info(''+str(j)+'次滑動設備wifi未找到,2s后進行下一次尋找')try:WebDriverWait(self.driver,10,1).until(lambda x:x.find_element_by_id('com.android.settings:id/password')).send_keys('11111111111111') #輸入密碼self.log.info('輸入密碼完成')time.sleep(2)WebDriverWait(self.driver,10,1).until(lambda x:x.find_element_by_xpath('//*[@text="連接"]')).click()self.log.info('點擊連接成功')except:self.log.info('連接按鈕沒找到(10s),WiFi未找到')def tearDown(self):pass@classmethoddef tearDownClass(cls):cls.driver.quit()if __name__ == "__main__":#import sys;sys.argv = ['', 'Test.testName']unittest.main()

?

轉載于:https://www.cnblogs.com/luobobobo/p/9679388.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389622.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389622.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389622.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

power bi中的切片器_在Power Bi中顯示選定的切片器

power bi中的切片器Just recently, while presenting my session: “Magnificent 7 — Simple tricks to boost your Power BI Development” at the New Stars of Data conference, one of the questions I’ve received was:就在最近,在“新數據之星”會議上介紹我…

字符串匹配 sunday算法

#include"iostream" #include"string.h" using namespace std;//BF算法 int strfind(char *s1,char *s2,int pos){int len1 strlen(s1);int len2 strlen(s2);int i pos - 1,j 0;while(j < len2){if(s1[i j] s2[j]){j;}else{i;j 0;}}if(j len2){…

5939. 半徑為 k 的子數組平均值

5939. 半徑為 k 的子數組平均值 給你一個下標從 0 開始的數組 nums &#xff0c;數組中有 n 個整數&#xff0c;另給你一個整數 k 。 半徑為 k 的子數組平均值 是指&#xff1a;nums 中一個以下標 i 為 中心 且 半徑 為 k 的子數組中所有元素的平均值&#xff0c;即下標在 i …

Adobe After Effects CS6 操作記錄

安裝 After Effects CS6 在Mac OS 10.12.5 上無法直接安裝, 需要瀏覽到安裝的執行文件后才能進行 https://helpx.adobe.com/creative-cloud/kb/install-creative-suite-mac-os-sierra.html , 但是即使安裝成功, 也不能正常啟動, 會報"You can’t use this version of the …

數據庫邏輯刪除的sql語句_通過數據庫的眼睛查詢sql的邏輯流程

數據庫邏輯刪除的sql語句Structured Query Language (SQL) is famously known as the romance language of data. Even thinking of extracting the single correct answer from terabytes of relational data seems a little overwhelming. So understanding the logical flow…

好用的模塊

import requests# 1、發get請求urlhttp://api.xxx.xx/api/user/sxx_infodata{stu_name:xxx}reqrequests.get(url,paramsdata) #發get請求print(req.json()) #字典print(req.text) #string,json串# 返回的都是什么# 返回的類型是什么# 中文的好使嗎# 2、發請求posturlhttp://api…

5940. 從數組中移除最大值和最小值

5940. 從數組中移除最大值和最小值 給你一個下標從 0 開始的數組 nums &#xff0c;數組由若干 互不相同 的整數組成。 nums 中有一個值最小的元素和一個值最大的元素。分別稱為 最小值 和 最大值 。你的目標是從數組中移除這兩個元素。 一次 刪除 操作定義為從數組的 前面 …

BZOJ4127Abs——樹鏈剖分+線段樹

題目描述 給定一棵樹,設計數據結構支持以下操作 1 u v d  表示將路徑 (u,v) 加d 2 u v 表示詢問路徑 (u,v) 上點權絕對值的和 輸入 第一行兩個整數n和m&#xff0c;表示結點個數和操作數接下來一行n個整數a_i,表示點i的權值接下來n-1行,每行兩個整數u,v表示存在一條(u,v)的…

數據挖掘流程_數據流挖掘

數據挖掘流程1-簡介 (1- Introduction) The fact that the pace of technological change is at its peak, Silicon Valley is also introducing new challenges that need to be tackled via new and efficient ways. Continuous research is being carried out to improve th…

北門外的小吃街才是我的大學食堂

學校北門外的那些小吃攤&#xff0c;陪我度過了漫長的大學四年。 細數下來&#xff0c;我最懷念的是…… &#xff08;1&#xff09;烤雞翅 吸引指數&#xff1a;★★★★★ 必殺技&#xff1a;酥流油 烤雞翅有蜂蜜味、香辣味、孜然味……最愛店家獨創的秘制雞翅。雞翅的外皮被…

786. 第 K 個最小的素數分數

786. 第 K 個最小的素數分數 給你一個按遞增順序排序的數組 arr 和一個整數 k 。數組 arr 由 1 和若干 素數 組成&#xff0c;且其中所有整數互不相同。 對于每對滿足 0 < i < j < arr.length 的 i 和 j &#xff0c;可以得到分數 arr[i] / arr[j] 。 那么第 k 個…

[LeetCode]最長公共前綴(Longest Common Prefix)

題目描述 編寫一個函數來查找字符串數組中的最長公共前綴。如果不存在公共前綴&#xff0c;返回空字符串 ""。 示例 1:輸入: ["flower","flow","flight"]輸出: "fl"示例 2:輸入: ["dog","racecar",&quo…

域嵌套太深_pyspark如何修改嵌套結構域

域嵌套太深In our adventures trying to build a data lake, we are using dynamically generated spark cluster to ingest some data from MongoDB, our production database, to BigQuery. In order to do that, we use PySpark data frames and since mongo doesn’t have …

redis小結

Redis 切換到redis的目錄 啟動&#xff1a;./redis-server 關閉&#xff1a;killall redis-server Redis的數據類型&#xff1a; String字符 list鏈表 set集合&#xff08;無序&#xff09; Sort Set排序&#xff08;有序&#xff09; hash數據類型 string類型的數據操作 re…

WIN10下ADB工具包安裝的教程和總結 --201809

ADB&#xff08;Android Debug Bridge&#xff09;是Android SDK中的一個工具, 使用ADB可以直接操作管理Android模擬器或者真實的Andriod設備。 ADB主要功能有: 在Android設備上運行Shell(命令行)管理模擬器或設備的端口映射在計算機和設備之間上傳/下載文件將電腦上的本地APK軟…

1816. 截斷句子

1816. 截斷句子 句子 是一個單詞列表&#xff0c;列表中的單詞之間用單個空格隔開&#xff0c;且不存在前導或尾隨空格。每個單詞僅由大小寫英文字母組成&#xff08;不含標點符號&#xff09;。 例如&#xff0c;“Hello World”、“HELLO” 和 “hello world hello world”…

spark的流失計算模型_使用spark對sparkify的流失預測

spark的流失計算模型Churn prediction, namely predicting clients who might want to turn down the service, is one of the most common business applications of machine learning. It is especially important for those companies providing streaming services. In thi…

峰識別 峰面積計算 peak detection peak area 源代碼 下載

原文:峰識別 峰面積計算 peak detection peak area 源代碼 下載Comparative analysis of peak-detection techniques for comprehensive two-dimensional chromatography http://www.docin.com/p-172045359.html http://terpconnect.umd.edu/~toh/spectrum/ipeak.html R…

區塊鏈開發公司談區塊鏈與大數據的關系

在過去的兩千多年的時間長河中&#xff0c;數字一直指引著我們去探索很多未知的科學世界。到目前為止&#xff0c;隨著網絡和信息技術的發展&#xff0c;一切與人類活動相關的活動&#xff0c;都直接或者間接的連入了互聯網之中&#xff0c;一個全新的數字化的世界展現在我們的…

Jupyter Notebook的15個技巧和竅門,可簡化您的編碼體驗

Jupyter Notebook is a browser bases REPL (read eval print loop) built on IPython and other open-source libraries, it allows us to run interactive python code on the browser.Jupyter Notebook是基于IPL和其他開源庫構建的基于REPL(讀取評估打印循環)的瀏覽器&#…