Advertisement
DeaD_EyE

selenium tab cycle

Dec 22nd, 2021
1,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import time
  2. from itertools import cycle
  3.  
  4. from selenium.webdriver import Chrome, ChromeOptions
  5.  
  6. options = ChromeOptions()
  7.  
  8. # https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification
  9. options.add_experimental_option("excludeSwitches", ['enable-automation'])
  10.  
  11. # fullscreen
  12. options.add_argument("--kiosk")
  13.  
  14. # profile for cookies tec.
  15. options.add_argument("--user-data-dir=chrome_profile")
  16.  
  17.  
  18. driver = Chrome(options=options)
  19.  
  20. # lazy way of putting urls in a list
  21. urls = "http://google.de http://golem.de http://heise.de http://bild.de".split()
  22.  
  23. # get the first url
  24. driver.get(urls[0])
  25.  
  26.  
  27. # now new tab -> get next url
  28. for url in urls[1:]:
  29.     driver.switch_to.new_window()
  30.     driver.get(url)
  31.    
  32.  
  33. # cycle through tabs
  34. for handle in cycle(driver.window_handles):
  35.     driver.switch_to.window(handle)
  36.     time.sleep(5)
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement