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
JavaScript
x
24
24
1
def base_dados_processos(self):
2
try:
3
df = pd.read_excel('TABLE.xlsx')
4
self.num_proc = df['COLUM']
5
except Exception:
6
pg.alert(text='error', title='ERROR', button='OK')
7
self.chrome.quit()
8
9
10
def loop_pesquisa(self):
11
for PROCESSOS in zip(self.num_proc):
12
num_current_tabs = len(self.chrome.window_handles)
13
if num_current_tabs < 3:
14
pg.hotkey('ctrl', '1')
15
time.sleep(1)
16
self.chrome.get('https://stackoverflow.com/')
17
pg.write(str(test))
18
pg.press('enter')
19
time.sleep(3)
20
pg.press('tab', presses=26)
21
pg.press('enter')
22
time.sleep(1)
23
pg.press('enter')
24
Advertisement
Answer
To do this, just add a loop that monitors the guides, it can be as follows:
JavaScript
1
3
1
while len(self.chrome.window_handles) > 3:
2
time.sleep(0.5)
3
without your code:
JavaScript
1
24
24
1
def base_dados_processos(self):
2
try:
3
df = pd.read_excel('TABLE.xlsx')
4
self.num_proc = df['COLUM']
5
except Exception:
6
pg.alert(text='error', title='ERROR', button='OK')
7
self.chrome.quit()
8
9
10
def loop_pesquisa(self):
11
for PROCESSOS in zip(self.num_proc):
12
while len(self.chrome.window_handles) > 3:
13
time.sleep(0.5)
14
pg.hotkey('ctrl', '1')
15
time.sleep(1)
16
self.chrome.get('https://stackoverflow.com/')
17
pg.write(str(test))
18
pg.press('enter')
19
time.sleep(3)
20
pg.press('tab', presses=26)
21
pg.press('enter')
22
time.sleep(1)
23
pg.press('enter')
24