Python Forum

Full Version: page navigation & form filling
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
OS: Windows 7, Python 3.6

I'm needing a command prompt script that will connect to a webpage and allow the user to log into the site using their username and password, asking user for the information and then simulate filling out the form and clicking the appropriate button to continue logging in. After entering the correct credentials I need the script to be able to simulate clicking on a series of buttons on the page, cycling through and adding the values in one of the columns depending on the value, (in this case adding up all the Cs or Ss and to finally tally at the end after clicking next to the last page of the table). I was going to use requests as it can fill out the form fields but it can not simulate clicking the buttons. So I decided to use "selenium" but so far all my script does is launch Chrome after I enter my credentials, I don't need it to actually launching the browser, and it's not even launching Chrome to the URL specified either. Any ideas/suggestions? Thanks.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

username = input("Input your username: ")
password = input("Input your password: ")

driver = webdriver.Chrome("C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe")
driver.get("URL.html")
assert "{PAGE-TITLE}" in driver.title

elem = driver.find_element_by_id("inptUserId")
elem.send_keys(username)
elem = driver.find_element_by_id("password")
elem.send_keys(password)
elem.send_keys(Keys.Return)

# the rest of the program will go here

driver.close()