Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. import time
  4. import json
  5. import sys
  6. import os
  7. import pyautogui
  8. import threading
  9.  
  10. sys.path.append(os.getcwd())
  11.  
  12. arquivoConf = os.path.join(os.getcwd(), sys.argv[1])
  13.  
  14. with open(arquivoConf) as json_data_file:
  15. config = json.load(json_data_file)
  16.  
  17. firefox_profile = webdriver.FirefoxProfile(config['from_nameFirefox'])
  18. browser = webdriver.Firefox(firefox_profile)
  19.  
  20. num_of_tabs = 10
  21.  
  22.  
  23. def restartTabs():
  24.  
  25. num_current_tabs = len(browser.window_handles)
  26.  
  27. # Fechar todas - 1 abas, deixando uma aberta para não fechar o navegador.
  28. for i in range(1, num_current_tabs):
  29. browser.window_handles[i]
  30. browser.close()
  31. time.sleep(2)
  32.  
  33. # Script para abrir as páginas.
  34. for total_new_tabs in range(1, num_of_tabs):
  35. browser.execute_script("window.open('','_blank');")
  36.  
  37. # Foca na última aba aberta
  38. browser.switch_to_window(browser.window_handles[-1])
  39. time.sleep(2)
  40.  
  41. # Fecha a aba remanescente das anteriormente fechadas.
  42. browser.windows_handles[0].close()
  43.  
  44. startTimer()
  45.  
  46. def startTimer():
  47. t = threading.Timer(30.0, restartTabs)
  48. t.start()
  49.  
  50. restartTabs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement