-
Notifications
You must be signed in to change notification settings - Fork 5
/
webautomation.py
134 lines (124 loc) · 4.61 KB
/
webautomation.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import pyautogui
import os
import time
import sys
import Images
# PyAutoGUI Failsafe Settings:
pyautogui.FAIL_SAFE = True
pyautogui.PAUSE = 1
def openfirefox():
#Open Firefox from OS
os.system('START "" Firefox')
time.sleep(3)
def findonscreen(imgpath,time):
find = pyautogui.locateOnScreen(imgpath,time,grayscale=False)
findx,findy = pyautogui.center(find)
return findx,findy
def setupproxy(proxyip,portno):
# Find Settings:
settingsfindx,settingsfindy = findonscreen('Images/settings.png',10)
pyautogui.click(settingsfindx,settingsfindy)
# Find Options:
optionsfindx,optionsfindy = findonscreen('Images/options.png',10)
pyautogui.click(optionsfindx,optionsfindy)
# Find Search:
searchfindx,searchfindy = findonscreen('Images/findinoptions.png',10)
pyautogui.click(searchfindx,searchfindy)
# Type Network in Search:
pyautogui.typewrite('Images/Network',0.2)
# Find Network Settings:
networkfindx,networkfindy = findonscreen('Images/networksettings.png',10)
pyautogui.click(networkfindx,networkfindy)
# Find Manual Proxy Config:
mproxyfindx,mproxyfindy = findonscreen('Images/manualproxyconfig.png',10)
pyautogui.click(mproxyfindx,mproxyfindy)
time.sleep(2)
pyautogui.press('tab')
pyautogui.typewrite(proxyip,0.2)
time.sleep(2)
pyautogui.press('tab')
pyautogui.typewrite(portno,0.2)
time.sleep(2)
pyautogui.press('tab')
pyautogui.press('space')
# Find Final_OK:
finalokfindx,finalokfindy = findonscreen('Images/finalok.png',10)
pyautogui.click(finalokfindx,finalokfindy)
print("--->New Proxy Set! Now moving on further procedure!")
def addnewtab():
tabbuttonx,tabbuttony = findonscreen('Images/newtab.png',10)
pyautogui.click(tabbuttonx,tabbuttony)
print("--->New Tab Opened!")
def opengoogle():
addressbarx,addressbary = findonscreen('Images/addressbar.png',10)
pyautogui.click(addressbarx,addressbary)
pyautogui.typewrite('http://google.com',0.2)
pyautogui.press('enter')
time.sleep(10)
def getsearchgoingon():
print("\n4] Browser Work Started!!")
pyautogui.typewrite('IP',0.2)
pyautogui.press('enter')
# gsearchx,gsearchy = findonscreen('/gsearch.png',10)
# pyautogui.click(gsearchx,gsearchy)
def settingscleanup():
# Opening Settings:
cleanupsettingsx,cleanupsettingsy = findonscreen('Images/settings.png',10)
pyautogui.click(cleanupsettingsx,cleanupsettingsy)
# Opening Options:
cleanupoptionsx,cleanupoptionsy = findonscreen('Images/options.png',10)
pyautogui.click(cleanupoptionsx,cleanupoptionsy)
# Opening Find:
cleanupsearchx,cleanupsearchy = findonscreen('Images/findinoptions.png',10)
pyautogui.click(cleanupsearchx,cleanupsearchy)
pyautogui.typewrite('Network',0.2)
time.sleep(1)
# Open Network Settings:
cleanupnetworkfindx,cleanupnetworkfindy = findonscreen('Images/networksettings.png',10)
pyautogui.click(cleanupnetworkfindx,cleanupnetworkfindy)
# Finding the Protocol:
cleanupprotocolx,cleanupprotocoly = findonscreen('Images/cleanupprotocol.png',10)
pyautogui.click(cleanupprotocolx,cleanupprotocoly)
# Clearing up the HTTP Proxy IP:
cleanuphttpproxyx,cleanuphttpproxyy = findonscreen('Images/cleanuphttpproxy.png',10)
pyautogui.click(cleanuphttpproxyx,cleanuphttpproxyy)
for i in range(0,16):
pyautogui.press('backspace')
print("--->Proxy IP Cleared!")
time.sleep(2)
pyautogui.press('tab')
pyautogui.press('delete')
print("--->Port Cleared!")
# Set No Proxy:
cleanupnomproxyx,cleanupnomproxyy = findonscreen('Images/cleanupnoproxy.png',10)
pyautogui.click(cleanupnomproxyx,cleanupnomproxyy)
# Final OK:
cleanupfinalokx,cleanupfinaloky = findonscreen('Images/finalok.png',10)
pyautogui.click(cleanupfinalokx,cleanupfinaloky)
print("--->Clean Up Done!")
if __name__ == '__main__':
print("\n1] Opening a new Firefox Instance!")
openfirefox()
browserExe = "Firefox.exe"
time.sleep(5)
try:
print("\n2] Checking if previosuly Proxy is already set!")
settingscleanup()
# os.system("taskkill /f /im "+browserExe)
except Exception as e:
print(e)
finally:
print("\n3] Setting up new Proxy!!")
setupproxy('1.1.1.1','1111')
time.sleep(1)
addnewtab()
time.sleep(1)
opengoogle()
time.sleep(1)
getsearchgoingon()
time.sleep(5)
pyautogui.hotkey('ctrl','w')
print("\n5] Process Completed!")
time.sleep(2)
print("\n6] Closing all Firefox Instances!!")
os.system("taskkill /f /im "+browserExe)