【问题标题】:Function from imported other Sikuli scripts not works导入的其他 Sikuli 脚本的功能不起作用
【发布时间】:2018-03-01 15:40:53
【问题描述】:

这是名为 switch_to_apps.sikuli

的 sikuli 脚本中的函数
def go_to_apps():
    if exists(Pattern("1505400746884.png").similar(0.85)):
        click(Pattern("1505400746884.png").similar(0.85))
        wait(2)
        if exists("1505400452627.png"):

            wait("1505746343759.png",FOREVER)

            click("1505745789021.png")

        else:
            click(Pattern("1505401581163.png").similar(0.95))

    else:
        click(Pattern("1505400343997.png").similar(0.80))
        if exists("1505400452627.png"):
            wait("1505746343759.png",FOREVER)

            click("1505745789021.png")
        else:
            click(Pattern("1505401581163.png").similar(0.95))

我将此脚本导入另一个脚本(主脚本)并调用函数go_to_apps()

type("r", Key.WIN)
wait(1)
type ("***************" + Key.ENTER)

wnd= App ("*********.exe")

while not wnd.isRunning():
    wait(1)


if exists(Pattern("1505813384072.png").similar(0.85)):
    pass
else:    
    popup("ERROR")


import switch_to_apps
go_to_apps()

wait (5)

rightClick(Pattern("1504795371766.png").similar(0.80))
wait(1)
click(Pattern("1504795615700.png").targetOffset(-75,80))

但 IDE 说我:

[error] NameError(名称'go_to_apps'未定义)

如果我首先打开 switch_to_apps.sikuli 脚本并运行函数 go_to_apps(),在该函数完成工作后,我运行主脚本,现在一切正常。 p>

我需要这样做,我的导入脚本中的函数可以正常工作吗?

【问题讨论】:

  • 那个定义go_to_apps()在课堂上吗?
  • 不,不在课堂上……

标签: automated-tests sikuli


【解决方案1】:

也许你会使用from switch_to_apps import *,而不是import switch_to_apps
或者可能是switch_to_apps.go_to_apps(),而不是go_to_apps()

我在课堂上有我的定义,所以我认为它可能会有点不同然后失去定义。

【讨论】:

  • 没错! from switch_to_apps import * 工作!谢谢
猜你喜欢
  • 1970-01-01
  • 2022-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-02
  • 1970-01-01
  • 2013-04-05
相关资源
最近更新 更多