title: Switch to a YouTube channel from a text file? (selenium)
body: <p>I've made a script that will log me into my YouTube account, go to the Youtube landing page, click on my channel logo, then click on &quot;switch account&quot;.</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.common.by import By
  import undetected_chromedriver as uc
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.support import expected_conditions as EC
  from selenium.webdriver.common.action_chains import ActionChains
  import time
  
  driver = uc.Chrome(use_subprocess=True)
  
  driver.get(&quot;https://accounts.google.com/ServiceLogin/identifier?service=youtube&amp;uilel=3&amp;passive=true&amp;continue=https&quot;
             &quot;%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26hl%3Den%26next%3Dhttps&quot;
             &quot;%253A%252F%252Fwww.youtube.com%252F&amp;hl=en&amp;ec=65620&amp;flowName=GlifWebSignIn&amp;flowEntry=ServiceLogin&quot;)
  
  f = open('Login.txt')
  lines = f.read().splitlines()
  f.close()
  Username = lines[0]
  Password = lines[1]
  
  
  element = driver.find_element(By.XPATH, '//*[@id=&quot;identifierId&quot;]')
  element.send_keys(Username)
  time.sleep(5)
  element.send_keys(Keys.RETURN)
  time.sleep(5)
  element = driver.find_element(By.XPATH, '//*[@id=&quot;password&quot;]/div[1]/div/div[1]/input')
  element.send_keys(Password)
  element.send_keys(Keys.RETURN)
  time.sleep(4)
  driver.get(&quot;https://youtube.com&quot;)
  wait = WebDriverWait(driver, 10)
  WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id=&quot;avatar-btn&quot;]'))).click()
  time.sleep(4)
  WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id=&quot;endpoint&quot;]'))).click
  time.sleep(2)
  </code></pre>
  <p>I'm wanting to make it so that I can enter my channel names in a text file (in same path as script), then match the names on the account list with the channel names on Youtube, and then click on where that name is located so I can switch to that channel.</p>
  <p>I've tried some code that I guessed since I couldn't find anything on this subject. Can someone please let me know how I can alter my code to achieve my goal? Thanks a lot.</p>
  <p><strong>Guessed code:</strong></p>
  <pre><code>f = open('Channel Names.txt')
  lines = f.read().splitlines()
  f.close()
  Channel1 = lines[0]
  Channel2 = lines[1]
  
  driver.find_element(By.NAME, Channel1).click()
  time.sleep(3)
  WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id=&quot;avatar-btn&quot;]'))).click()
  time.sleep(2)
  WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id=&quot;endpoint&quot;]'))).click
  time.sleep(2)
  WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, Channel2))).click()
  time.sleep(3)
  </code></pre>