I have a problem to login on twitch with selenium. After the bot has entered the credentials (I also tried to enter them manually) the error message appears: "Something went wrong. Please try again." And it won't let me in.
Any suggestions?
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
def start_twitch_viewer():
PATH = r"./Local/twitch-stream-viewer/chromedriver"
email = 'username@gmail.com'
usr = 'Username'
pswd = 'Password'
chrome_options = webdriver.ChromeOptions()
try:
driver = webdriver.Chrome(PATH, options=chrome_options)
driver.get("https://www.twitch.tv/ChannelName")
driver.header_overrides = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"}
except:
return
time.sleep(10)
driver.find_element(By.CSS_SELECTOR, "div[class='Layout-sc-nxg1ff-0 csWXEI']").click()
time.sleep(5)
username=driver.find_element(By.CSS_SELECTOR, "input[id='login-username']")
password=driver.find_element(By.CSS_SELECTOR, "input[id='password-input']")
username.clear()
password.clear()
username.send_keys(usr)
password.send_keys(pswd)
time.sleep(5)
driver.find_element(By.CSS_SELECTOR, "div[class='Layout-sc-nxg1ff-0 OZCSg']").click()
time.sleep(1000)
if __name__ == "__main__":
start_twitch_viewer()
EDIT: This is the file based on the suggestion given by @Lenta.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("user-data-dir=/Users/usr/Library/Application Support/Google/Chrome")
chrome_options.add_argument("profile-directory=Profile 3")
chrome_options.add_experimental_option("detach", True)
try:
driver = webdriver.Chrome(executable_path=PATH, options=chrome_options)
driver.set_window_position(0, 0)
driver.set_window_size(1440, 900)
driver.get("https://www.twitch.tv/user")
except:
return