sikuli常见问题解决

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

如何在脚本中使用汉字
• 请参考 /dev/peps/pep-0263/ • 解决方案:
在脚本文件的前面添加如下代码: #!/user/bin/python # -*- coding: utf-8 -*(必须放在脚本文件的第一行,试过)
如何在log中显示日期

you may find, that your dropdown entry is found even if the content is not exactly, what the image says. To test different situations, produce these situations and then use preview (click on the image in the IDE). Play around with the similarity slider. • if you click ok, your image is turned into a pattern object (pattern(image).similar(decimal between 0 and 1). • You can use it directly (use instead of find(<image>): find(Pattern(<image>).similar(0.8)) # the standard in the moment is 0.73 this means: only find images with a similarity of at least 0.8 This helped in the example to assure, that the dropdown was only clicked when showing: by relevancy.
如何更改匹配相识度
• 参考 /docx/globals.html#controlling -sikuli-scripts-and-their-behavior • 解决方案:
Settings.MinSimilarity=(小于1的数字) 默认0.7
如何指定一个相对的位置,并点击
• 参考 (Extending a Region) /docx/region.html#creating-aregion-setting-and-getting-attributes • 解决方案:
location =find("ii-1.png").right(50) hover(location) mouseDown(Button.LEFT) mouseUp(Button.LEFT) 或者 Location=Pattern(“ii-1.png”).targetOffset(100,0)参 考/docx/pattern.html
• 解决方案:
import datetime now = datetime.datetime.now() print now.strftime('%Y-%m-%d %H:%M:%S')
如何将数字转换成字符串
• 参考 /1041109/78816 6 • 解决方案:
• • • • •
如何更改匹配相识度 如何指定一个相对位置并点击 如何设置鼠标移动延迟 如何等待一个图像的出现 如何取得一个图像的坐标
如何实现拖拽
• ip = App("iPhone Simulator") ip.focus() ipw = ip.window() #ipw.highlight(2) bottom = "1318343141834.png" # see comment mBottom = ipw.find(bottom) p = mBottom.getTopLeft().above(10).right(15) hover(p) mouseDown(Button.LEFT) mouseMove(p.above(100)) mouseUp()
如何设置鼠标移动延迟
• 参考 /docx/globals.html#controlling -sikuli-scripts-and-their-behavior • 解决方案:
Settings.MoveMouseDelay=数值 以s为单位,默认为0.5s
• •
如何取得一个图像的坐标
• 参考 • https:///sikuli/+questio n/110634
• The only modification needed is to use below instead of down x1, y1, x2, y2 = (100, 100, 500, 600) start = Location(x1, y1) end = Location(x2, y2) stepX = 10 # adjust this as needed stepY = int((y2-y1)/((x2-x1)/stepX)) run = start mouseMove(start); wait(0.5) mouseDown(Button.LEFT); wait(0.5) while run.getX() < end.getX(): run = run.right(stepX).below(stepY) # use below instead of down mouseMove(run) mouseMove(end) mouseUp()
globalbar告诉python下面的bar是全局的bar这里是全局变量printbar打出hello全局的bar已经改为hello不再是python了解决方案
Sikuli常见问题
常见问题
• • • • • • • 如何实现拖拽 如何操作下拉列表框 如何在脚本中使用中文 如何在log中显示日期 如何将数字转换成字符串 如何定义全局变量 Sikuli打不开怎么办
Sikuli打不开咋办
• 参考 https:///sikuli/+faq/17 66 • 解决方案:
– On windows: – Use Sikuli-IDE.bat to start sikuli – Before delete the registry branch HKEY_CURRENT_USER\Software\JavaSoft\Prefs\or g\sikuli\ide\
str(数字)
如何定义全局变量
• python有全变量,一般跟c里面是一样的
bar = 'python‘ def foo1(): bar = 'hello' # 这里是局部变量 print(bar) # 打出hello,并且不会影响全局变量bar(全局那个bar仍 然是'python') def foo2(): print(bar) # 打出python # 因为没有声明局部变量所以python会搜 索全局的bar,这个bar是全局的 def foo3(): global bar # 告诉python下面的bar是全局的 bar = 'hello' # 这里是全局变量 print(bar) # 打出hello,全局的bar已经改为hello不再是python了 解决方案: 在函数外面定义变量,然后在函数体内用global声明后在使用
如何操作下拉列表框
• switchApp("Safari") dd = find(<image of your drop down in closed situation> ) if dd: click(dd) # opens list sleep(0.5) # to avoid timing problems type(Key.DOWN) # here goes your navigation type(Key.ENTER) else: popup("Sorry, no dropdown found")
• while not ipw.exists (image-of-delete-button, 0): hover(p) mouseDown(Button.LEFT) mouseMove(p.above(100)) # choose your stepping mouseUp() wait(1) clickቤተ መጻሕፍቲ ባይዱipw.getLastMatch()) # should click delete button
• • • •
• 解决方案: • #定义一个函数,等待一个图像出现,图像出现就退出 • def waitFor(img): • weWait=30 • while weWait > 0: • result = exists(img,0) • if result: • break • wait(1) • weWait-=1 • if not result: • print "image did not appear" • exit(1)
如何等待一个图像的出现 参考https:///sikuli/+faq/1568
# img1 and img2 contain valid image filenames weWait = 20 # max seconds we want to wait while weWait > 0: mImg1 = exists(img1,0) # see comment mImg2 = exists(img2,0) if mImg1 or mImg2: break # leave the loop if at least one found wait(1) weWait -= 1 # count down wait time if not (mImg1 and mImg2): print "images did not appear"; exit(1) if mImg1: print "image 1 appeared if mImg2: print "image 2 appeared --- comment exists(img,0) does only one search and does not wait the standard 3 seconds, if image is not found. So for timing purposes you can calculate 0.5 seconds for every exists. So in your case it will last about 25 to 30 seconds, if n one of the images appears. So if 20 seconds is what you want, set weWait to an appropriate lower value (e.g. 15).
相关文档
最新文档