1

I'm writing a script where I need you to monitor the number of open tabs. The script reads a table and each information in the table opens a new tab in the browser. It turns out that in order not to have thousands of tabs open, I need the script to monitor the tabs to have only 3 open, when I close a tab I need to automatically open the next tab

def base_dados_processos(self):
    try:
        df = pd.read_excel('TABLE.xlsx')
        self.num_proc = df['COLUM']
    except Exception:
        pg.alert(text='error', title='ERROR', button='OK')
        self.chrome.quit()


def loop_pesquisa(self):
    for PROCESSOS in zip(self.num_proc):
        num_current_tabs = len(self.chrome.window_handles)
        if num_current_tabs < 3:
            pg.hotkey('ctrl', '1')
            time.sleep(1)
            self.chrome.get('https://stackoverflow.com/')
            pg.write(str(test))
            pg.press('enter')
            time.sleep(3)
            pg.press('tab', presses=26)
            pg.press('enter')
            time.sleep(1)
            pg.press('enter')

1 Answer 1

1

To do this, just add a loop that monitors the guides, it can be as follows:

while len(self.chrome.window_handles) > 3:
            time.sleep(0.5)

without your code:

def base_dados_processos(self):
    try:
        df = pd.read_excel('TABLE.xlsx')
        self.num_proc = df['COLUM']
    except Exception:
        pg.alert(text='error', title='ERROR', button='OK')
        self.chrome.quit()


def loop_pesquisa(self):
    for PROCESSOS in zip(self.num_proc):
        while len(self.chrome.window_handles) > 3:
            time.sleep(0.5)
        pg.hotkey('ctrl', '1')
        time.sleep(1)
        self.chrome.get('https://stackoverflow.com/')
        pg.write(str(test))
        pg.press('enter')
        time.sleep(3)
        pg.press('tab', presses=26)
        pg.press('enter')
        time.sleep(1)
        pg.press('enter')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.