正规网站制作公司哪家好,自己做购物网站推广,手机里面的网站怎么制作,便宜网站建设公司前言#xff1a; 此篇是介绍怎么去寻找蓝牙#xff0c;进行匹配。主要2个问题点#xff1a; 1.在不同环境下#xff0c;搜索到的蓝牙数量有变 2.在不同环境下#xff0c;搜索到的蓝牙排序会变 简单思路#xff1a; 将搜索出来的蓝牙名字添加到一个list去#xff0c;然后…前言 此篇是介绍怎么去寻找蓝牙进行匹配。主要2个问题点 1.在不同环境下搜索到的蓝牙数量有变 2.在不同环境下搜索到的蓝牙排序会变 简单思路 将搜索出来的蓝牙名字添加到一个list去然后在去匹配list里是否有你要匹配的蓝牙找到了就点击没找到又进行下一次寻找知道找到为止 简单代码 #coding:utf-8
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import time
bluetoothNameiPhone
desired_caps {platformName: Android,deviceName: 9a762346,platformVersion: 6.0.1,noReset: True,appPackage: com.android.settings,appActivity: .Settings}
driverwebdriver.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(搜索完毕)
adriver.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)x1size[width] * 0.5y1size[height] * 0.75y2size[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(//*[textiPhone])).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.driverwebdriver.Remote(http://127.0.0.1:4723/wd/hub, desired_caps)cls.baseBaseApp(cls.driver)cls.logLog()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(//*[textWLAN])).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搜索完毕)aself.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(//*[textiPhone罗])).click()self.log.info(第str(j)次滑动设备找到wifi)self.log.info(b)break else:x1self.size[width] * 0.5y1self.size[height] * 0.75y2self.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):passclassmethoddef tearDownClass(cls):cls.driver.quit()if __name__ __main__:#import sys;sys.argv [, Test.testName]unittest.main() 转载于:https://www.cnblogs.com/luobobobo/p/9679388.html