1
I need this code of mine every hour to make the process of reopening all tabs or setting up or just closing everything and running this code every hour. Has as?
from selenium import webdriver
import time
import json
import sys
import os
import pyautogui
if len(sys.argv) <= 1:
print ("Como usar:\n\t" + sys.argv[0] + " config.txt")
sys.exit()
sys.path.append(os.getcwd())
arquivoConf = os.path.join(os.getcwd(), sys.argv[1])
with open(arquivoConf) as json_data_file:
config = json.load(json_data_file)
firefox_profile = webdriver.FirefoxProfile(config['from_nameFirefox'])
browser = webdriver.Firefox(firefox_profile)
def fazerLogin():
browser.get('about:preferences')
browser.execute_script('document.getElementById("linkTargeting").click();')
browser.get(config['url'])
user = browser.find_element_by_name('j_username')
password = browser.find_element_by_name('j_password')
user.send_keys(config['user'])
password.send_keys(config['pass'])
browser.find_element_by_id('submitButton').click();
time.sleep(10)
def desceQnt(valor):
#print ( '--->' + str(valor))
for i in range(0, valor):
#print ( '->' + str(1))
pyautogui.press('down')
time.sleep(2)
pyautogui.press('enter')
def passarEntreTabs():
# Volta para primeiro Dashboard
pyautogui.click(config['posicaoElemento'][0], config['posicaoElemento'][1])
pyautogui.press('home')
time.sleep(2)
pyautogui.press('enter')
for i in range(1, config['countDashboard']):
browser.execute_script('window.open("' + config['url'] + ' ", "_blank");')
time.sleep(config['carregar_tela'])
pyautogui.moveTo(config['posicaoElemento'][0], config['posicaoElemento'][1], duration= 2)
pyautogui.click(config['posicaoElemento'][0], config['posicaoElemento'][1])
time.sleep(3)
pyautogui.press('home')
desceQnt(i)
time.sleep(3)
print ( 'Fechando Ultima Aba' )
browser.window_handles[0]
browser.execute_script('window.open("","_self").close()')
os.system('cls')
print ( 'Setup configurado ')
print ( time.strftime("%Y-%m-%d %H:%M") )
print ( 'Entrando no While TRUE')
#def fecharPorra():
fazerLogin()
passarEntreTabs()
while True:
numberOfTabs = len(browser.window_handles)
for i in range(0, numberOfTabs):
browser.switch_to_window(browser.window_handles[i])
if ( browser.current_url == config['url'] ):
browser.execute_script('document.getElementsByTagName("img")[1].click();window.frames[0].loadDashboardLayout();')
else:
browser.execute_script('location.reload();')
time.sleep(config['tempo_Refrash'])
What’s the difference to this question?
– Woss
I’m using another script and logic. Also I put this possibility open "configure or just close everything and run this code every hour".
– Romulo Sousa