0

I have a problem with loops in PyQt5
can someone tell me how to replace or how to use loops using PyQt5?

I tried to find solution, but I failed.

Here is part of code which I want to have under infinity loop.

I also tried to make it with - do while button is not clicked.

 while(1):
            try:
                print("Working")
                finallmoney = "";
                money = driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[1]/header[1]/div[2]/ul[1]/li[3]/p[1]")
                text = driver.find_element_by_xpath(f"/html[1]/body[1]/div[1]/div[1]/main[1]/div[1]/div[1]/div[2]/div[1]/div[{self.a}]/div[1]/div[2]/div[3]/div[2]/span[1]")
                text2 = driver.find_element_by_xpath(f"/html[1]/body[1]/div[1]/div[1]/main[1]/div[1]/div[1]/div[2]/div[1]/div[{self.b}]/div[1]/div[2]/div[3]/div[2]/span[1]")
                cost1 = driver.find_element_by_xpath(f"//div[{self.a}]//div[1]//div[2]//div[3]//div[1]//span[1]")
                cost2 = driver.find_element_by_xpath(f"//div[{self.b}]//div[1]//div[2]//div[3]//div[1]//span[1]")
                how_much_wait = int(re.search(r'\d+', text.text).group())
                how_much_wait2 = int(re.search(r'\d+', text2.text).group())
                price1=int(re.search(r'\d+', cost1.text).group())
                price2=int(re.search(r'\d+', cost2.text).group())
                money = re.findall(r'\d+', money.text)
                for x in money:
                    finallmoney +=x
                money = int(finallmoney)
                print(f"Na koniec treningu 1 umiejetnosci trzeba czekac:{how_much_wait}, cena treningu:{price1}")
                print(f"Na koniec treningu 2 umiejetnosci trzeba czekac:{how_much_wait2}, cena treningu:{price2}")
                if price2 > price1:
                    price1 = price2
                if how_much_wait2 > how_much_wait:
                    how_much_wait = how_much_wait2
                if price1>money:
                    print("Koniec pieniedzy na koncie w grze, koncze dzialanie bota")
                    sys.exit(0)
                print(f"Ilosc pieniedzy na koncie:{money}")
                count = count + 2
                print(f"BOT wykonał już {count} treningow!")

                wheretomove =  driver.find_element_by_xpath(f"/html[1]/body[1]/div[1]/div[1]/main[1]/div[1]/div[1]/div[2]/div[1]/div[{self.a}]")
                hover = ActionChains(driver).move_to_element(wheretomove)
                hover.perform()
                ele = driver.find_element_by_xpath(f"/html[1]/body[1]/div[1]/div[1]/main[1]/div[1]/div[1]/div[2]/div[1]/div[{self.a}]/div[1]/div[2]/button[1]")
                ele.click()

                wheretomove =  driver.find_element_by_xpath(f"/html[1]/body[1]/div[1]/div[1]/main[1]/div[1]/div[1]/div[2]/div[1]/div[{self.b}]")
                hover = ActionChains(driver).move_to_element(wheretomove)
                hover.perform()
                ele = driver.find_element_by_xpath(f"//div[{self.b}]//div[1]//div[2]//button[1]")
                ele.click()

                time.sleep(how_much_wait+2)
            except InvalidElementStateException as e:
                print("===BOT nie moze wcisnac guzika! Ponizej wiecej szczegolow!===")
                print(e)
            except NoSuchElementException as e:
                print("===BOT nie moze znalezc guzika! Ponizej wiecej info!===")
                print(e)
            except ElementClickInterceptedException as e:
                print("===BOT nie moze wcisnac guzika, poniewaz jest czyms zakryty!===")
                print(e)
        return
Styles
  • 26
  • 2
  • 2
    Please clarify your question by explaining what you want to achieve and, most importantly, provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – musicamante Jan 27 '20 at 14:32
  • You need to move the infinite loop to a different thread to avoid blocking the main event loop. See for example [this question](https://stackoverflow.com/questions/6783194/background-thread-with-qthread-in-pyqt) to get an idea how to do this. – Heike Jan 27 '20 at 15:15

0 Answers0