-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (62 loc) · 1.83 KB
/
main.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
import sys, getopt, time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
def enterText(driver, elementId, text):
try:
driver.find_element_by_id(elementId).send_keys(text)
except NoSuchElementException:
print("No", elementId, "element")
def clickButton(driver, elementId):
try:
driver.find_element_by_id(elementId).click()
except NoSuchElementException:
print("No", elementId, "element")
def main(argv):
username = ''
password = ''
try:
opts, args = getopt.getopt(argv, "hu:p:", ["username=", "password="])
except getopt.GetoptError:
print('Invalid option')
print('test.py -i <inputfile> -o <outputfile>')
exit()
for opt, arg in opts:
if opt == '-h':
print('test.py -u <username> -p <password>')
exit()
elif opt in ("-u", "--username"):
username = arg
elif opt in ("-p", "--password"):
password = arg
if len(username) == 0:
print('Username not entered')
print('test.py -u <username> -p <password>')
exit()
if len(password) == 0:
print('Password not entered')
print('test.py -u <username> -p <password>')
exit()
# if len(csv) == 0:
# print('CSV not entered')
# print('test.py -u <username> -p <password> -c <csv>')
# exit()
#Try using chrome webdriver first. If that fails use Firefox
driver = None
# try:
driver = webdriver.Chrome()
# except FileNotFoundError:
# print('Chrome web driver not found')
# print('Trying Firefox')
# try:
# driver = webdriver.Firefox()
# except FileNotFoundError:
# print('Firefox web driver not found')
# exit()
#Start selenium and go to login jpage
driver.get("https://www.portfolio123.com/login.jsp?url=/")
#Enter credentials and login
enterText(driver, "LoginUsername", username)
enterText(driver, "LoginPassword", password)
clickButton(driver, "Login")
if __name__ == "__main__":
main(sys.argv[1:])