Python while / if循环忽略条件

时间:2019-06-25 15:55:37

标签: python while-loop pyautogui

我正在编写一个基本的while/if循环以在nextbutton.png不在屏幕上时向下滚动页面,并在按钮在屏幕上时停止滚动。

如果按钮不在屏幕上,它将打印True,如果按钮在屏幕上,则应该打印True True True True True True True True True True True True True True False 。 问题是,当我运行此代码时,得到以下输出:

False

编写此代码的方式,永远不要输出True或位置信息import pyautogui while True: if pyautogui.locateOnScreen('nextbutton.png', confidence=0.9) is None: print(pyautogui.locateOnScreen('nextbutton.png', confidence=0.9) is None) time.sleep(random.randint(0,3000)/1000) pyautogui.press('pagedown') else: x4, y4 = pyautogui.locateCenterOnScreen('nextbutton.png', confidence=0.9) print(x4,y4) break 。我可以向我尝试的网站提供有关如何复制输出的说明,但是我怀疑在构造循环时犯了一个简单的逻辑错误。

public  class Foo {
    public void printClassName() {
        System.out.println(this.getClass().getName());
    }
}

1 个答案:

答案 0 :(得分:2)

您两次调用函数/.*topic="(?:[AB_CD_EF_(GH_)]{2,3}_)+([^_]]+).*/ ,每次函数可能返回不同的输出。

我建议使用变量来保存locateOnScreen()的输出,以避免出现这种竞争情况。也许这可以为您工作:

locateOnScreen()