-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
cross-browser.py
63 lines (47 loc) · 1.61 KB
/
cross-browser.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
author: @endormi
Automated cross browser testing
Even if some of the browsers do not work, running this code works
"""
from selenium import webdriver
import pyautogui
import time
web_browser = {}
def test_browsers(wd):
try:
"""
Include all of the browsers that have a official webdriver according to the selenium website
Look at the https://selenium.dev/downloads/ docs on how to set all of them up
"""
web_browser = {
'Firefox': webdriver.Firefox,
'Edge': webdriver.Edge,
'Ie': webdriver.Ie,
'Safari': webdriver.Safari,
'Opera': webdriver.Opera,
}
if wd == 'Chrome':
browser = webdriver.Chrome(r'file/to/driver/if/needed/otherwise/remove/r')
else:
browser = web_browser.get(wd)()
browser.maximize_window()
return browser
except Exception as msg:
print(msg)
def test_python_search(wd):
browser = test_browsers(wd)
browser.get('https://www.python.org/')
time.sleep(1)
browser.find_element_by_id('id-search-field').send_keys('style guide')
time.sleep(1)
pyautogui.typewrite(['enter'])
time.sleep(2)
browser.find_element_by_xpath('/html/body/div/div[3]/div/section/form/ul/li[1]/h3/a').click()
time.sleep(1)
browser.find_element_by_xpath('/html/body/div/div[3]/div/section/article/p[2]/i/a[1]').click()
time.sleep(1)
print(browser.current_url)
if __name__ == "__main__":
browsers = ['Chrome', 'Firefox', 'Edge', 'Ie', 'Safari', 'Opera']
for list in browsers:
test_python_search(list)