Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login to web application
#1
Hello,

I am using many environments of an application in my work. Each environment has a different URL.

I am using the webbrowser module to quickly open the app in a particular environment from the windows CMD. See the code below.

Now I want to go further and once the application is open in a browser then to log in automatically.

I found that I could use selenium to automatically log in.
The point is that my application is working in IE 11 only and selenium seems to be not working with IE 11. I had to make some entries to the registry but still getting errors.

My question is how to log in to the web app not using selenium?

import webbrowser, sys

url = 'google.com'

if len(sys.argv) > 1:
    arg = str(sys.argv[1]).upper()
else:
    arg = ""

prod='https://produrl'
uat='https://uat'
sit='http://sit'
dev='http://dev'
reftest='http://reftest'
refqa='http://refqa'
refdev='http://dev'

if arg == 'PROD':
    url = prod
elif arg == 'UAT':
    url = uat
elif arg == 'SIT':
    url = sit
elif arg == 'DEV':
    url = dev
elif arg == 'REFTEST':
    url = reftest
elif arg == 'REFQA':
    url = refqa
elif arg == 'REFDEV':
    url = refdev
else:
	if arg:
		url = 'unknown'
	else:
		url = 'none'

if url == 'none':
	print ('W parametrze musisz podać nazwę środowiska...')
elif url == 'unknown':
	print ('Nie znam takiego środowiska...%s' %(arg))
else:
	webbrowser.get(webbrowser.iexplore).open_new_tab(url)
	print ('Otwieram...%s' %(arg))
Reply
#2
first of all, your code can be shortened to
import webbrowser, sys
 
urls = {'prod':'https://produrl', 'uat':'https://uat', 'sit':'http://sit',
        'dev':'http://dev', 'reftest'='http://reftest', 'refqa':'http://refqa'
        'refdev':'http://dev'}
 
if len(sys.argv) == 1:
    print ('W parametrze musisz podać nazwę środowiska...')
else:
    arg = sys.argv[1].lower()
    url = urls.get(arg, None)
    if url:
        webbrowser.get(webbrowser.iexplore).open_new_tab(url)
        print ('Otwieram {}...'.format(arg))
    else:
        print ('Nie znam takiego środowiska {}...'.format(arg))
not sure if it will work but you may try to use some of the modules like pywinauto, pyautogui
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020