-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathselenium_ok_alert.py
More file actions
32 lines (26 loc) · 1.3 KB
/
selenium_ok_alert.py
File metadata and controls
32 lines (26 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import time
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.common import NoAlertPresentException
options = ChromeOptions()
options.add_argument('--start-maximized')
options.add_argument("force-device-scale-factor=0.95")
driver = Chrome(options=options)
urls = ['https://web.archive.org/web/20080221233711/http://www.berkshire.com/',
'https://web.archive.org/web/20171107004101/http://www.berkshirefunds.com/',
'https://web.archive.org/web/20200224044229/http://www.berkshirefunds.com/']
for i, url in enumerate(urls):
driver.get(url)
time.sleep(5)
if url.endswith('www.berkshire.com/'):
target_element = driver.find_element(By.TAG_NAME, 'tbody')
target_element.screenshot(f'{i}_screen_capture.png')
elif url.endswith('www.berkshirefunds.com/'):
try:
# ---------------------------------------------------------------------------------------------
driver.switch_to.alert.accept()
# ---------------------------------------------------------------------------------------------
except NoAlertPresentException:
pass
target_element = driver.find_element(By.CSS_SELECTOR, 'div#page-wrap')
target_element.screenshot(f'{i}_screen_capture.png')