So I'm trying to implement a program using selenium that upvotes the top post in my mostly private subreddit. So far, I've been able to implement the logging in and clicking on the upvote button part but the votes aren't actually registering on Reddit as far as I can see. I'm fairly new to python and have learned most of the basics so I'm doing this just for the sake of experimentation and curiosity. Here's my code I would really appreciate it if you could maybe try to help me out.
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import TimeoutException
import os
import random
webs = input("Complete Post URL: ")
username = os.getenv("USERNAME")
userProfile = "C:\\Users\\" + username + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
chrome_options = Options()
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-javascript")
chrome_options.add_argument("--disable-rtc-smoothness-algorithm")
chrome_options.add_argument("--disable-webrtc-encryption")
chrome_options.add_argument("--disable-webrtc-hw-decoding")
chrome_options.add_argument("--incognito")
chrome_options.add_argument(
'--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/86.0.4240.75 Safari/537.36"')
chrome_options.add_experimental_option("excludeSwitches",
["ignore-certificate-errors", "safebrowsing-disable-download-protection",
"safebrowsing-disable-auto-update", "disable-client-side-phishing-detection",
"enable-automation"])
x = str(random.randint(700, 1920))
y = str(random.randint(700, 1080))
chrome_options.add_argument(f"--window-size={x,y}")
driver = webdriver.Chrome('chromedriver.exe', options=chrome_options)
driver.get("https://old.reddit.com")
user = driver.find_element_by_xpath('//*[@id="login_login-main"]/input[2]')
user.send_keys(useritem)
pwd = driver.find_element_by_xpath('//*[@id="login_login-main"]/input[3]')
pwd.send_keys(passitem)
login = driver.find_element_by_xpath('//*[@id="login_login-main"]/div[4]/button')
login.click()
time.sleep(3.45)
driver.get(webs)
xp = webs.split('/')
xp = xp[-3]
try:
time.sleep(5)
upvote = driver.find_element_by_xpath(f'//*[@id="upvote-button-t3_{xp}"]/span/i')
upvote.click()
print(useritem + " Upvoted!")
time.sleep(15)
driver.close()
except TimeoutException as t:
print(t.msg)