I'm writing a simple script to login a specific site, enter my credentials, and navigate to specific section. I'm using selenium to control Firefox and the first portion is working fine.
The next part is where I'm having issues.
Basically, after logging in and going Section1, I created a while loop that asks for an input from me. The inputs would be to navigate between different sections. I have 5 options here. The 5th one logs out of the site and quits the program.
I'm running this on Mac (terminal). The behavior I want is I only choose one of the options (1, 2, 3, 4, 5) to navigate between the different sections and/or logout and close the program.
Here's the code that code that comes after I open up Firefox, login, and go to section 1.
reply = ''
while reply == '':
print('''
What would you like to do next?
Enter the number to do the following:
1 - Go to Section 1
2 - Go to Section 2
3 - Go to Section 3
4 - Go to Section 4
5 - Logout and Quit
''')
reply = input()
if reply == 1: #Load Section 1
section1 = browser.find_element_by_id('id goes here')
section1.click()
elif reply == 2: #Load Section 2
print('Opening negotations...')
section2 = browser.find_element_by_id('id goes here')
section2()
elif reply == 3: #Load Section 3
section3 = browser.find_element_by_id('id goes here')
section3.click()
elif reply == 4: #Load Section 4
section4 = browser.find_element_by_id('id goes here')
section4.click()
elif reply == 5: #Logout and close browser
break
else:
print('Please choose from one of the options.')
print('Logging out...')
logout = browser.find_element_by_css_selector('css selector goes here')
logout.click()
time.sleep(3)
browser.quit()
All the individual find_element_by_css_selector or by_id_selector are working individually. I just can't get it to work inside the loop.
What's happening is that every time I get asked for the input (reply), no matter what my answer is, it logs out, i.e. performs the 5th option / out of the while loop.
I can't seem to understand what's causing it.
Some stuff I tried
Adding a continue after each if/elif like this:
if reply == 1: #Load Section 1
section1 = browser.find_element_by_id('id goes here')
section1.click()
continue
But still goes to the end of my code.