How to automate clicking profile picture of inactive streamer using Selenium?

I need help with automating clicks on profile pictures for streamers who are currently not broadcasting. When I visit a streamer’s page while they’re offline and try to click their profile image, it should redirect me to their offline broadcast page rather than staying on the main channel page.

I’m having trouble with my current selenium script. The element locator doesn’t seem to work properly. Here’s what I’ve tried so far:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("user-data-dir=C:\\Users\\myuser\\AppData\\Local\\Google\\Chrome\\profile")
browser = webdriver.Chrome(options=chrome_options)
browser.get('https://www.twitch.tv/somestreamer')

# attempting to locate and click the profile image
profile_pic = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "::before")))
profile_pic.click()

What’s the correct way to target the avatar element for inactive streamers?

Your browser’s hitting authentication or CORS issues. Twitch has heavy client-side rendering and anti-bot measures that mess with standard Selenium setups. I’ve worked with similar streaming sites before - using the right user agent string makes a huge difference. Add this to your chrome options:

chrome_options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")

Also check if you’re logged in - profile interactions need authentication. Hit twitch.tv first, verify you’re logged in, then go to the streamer page. That redirect might only work for authenticated users or certain account types.

Wait, does Twitch really redirect when you click profile pics of offline streamers? I’ve never seen that happen. Usually clicking the avatar just opens a user card or does nothing. Double-check you’re targeting the right element - there might be overlay divs catching the clicks instead.

Timing’s probably the issue here - Twitch loads everything asynchronously, so the profile image might not be ready when your script tries clicking it. I’ve seen this before where waiting for element_to_be_clickable doesn’t cut it on heavy JS sites like Twitch. Add an explicit wait after the page loads, then use a better selector strategy. Don’t just wait for one element - wait for the whole page structure to stabilize first. Also try scrolling to the element before clicking since some sites only make stuff interactive when it’s visible. Still getting weird results? Use ActionChains to hover over the element first, then click - helps with elements that have complex event handlers.

I hit the same problem automating Twitch stuff. The profile image element changes when streamers go live or offline, so your selectors keep breaking. Don’t chase specific selectors - use XPath with partial matching instead.

Here’s what works - let the page load completely, then target the avatar container:

from time import sleep

# Let page render first
sleep(3)

profile_pic = WebDriverWait(browser, 20).until(
    EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'avatar') or contains(@data-a-target, 'avatar')]//img"))
)
profile_pic.click()

Or just target the button wrapper directly since the image might not be clickable. Inspect the offline page and look for a button around the avatar - that’s what actually handles clicks.

Been there countless times with streaming platforms. Your selector isn’t the real problem - you’re fighting a DOM that changes constantly.

Twitch updates their frontend all the time, breaking hardcoded selectors every few weeks. Add dynamic loading, anti-bot stuff, and different states for live/offline streamers - it’s a mess.

Ditch the Selenium script that’ll need constant fixes. Build a proper automation workflow instead. It handles page loading, waits for elements, adapts to DOM changes, and retries with backup selectors when things fail.

You can monitor multiple streamers, handle different page states, and get logs when stuff breaks. Way more reliable than fragile Python scripts.

I’ve automated similar content monitoring tasks - saves hours of debugging selector headaches. Set it once, forget it.

Check out Latenode for this kind of web automation: https://latenode.com

Your code’s trying to find “::before” with LINK_TEXT, but that won’t work. ::before is a CSS pseudo-element, not actual text - Selenium can’t target those directly since they’re not in the DOM. I’ve scraped Twitch before and you need to target the actual image or its container instead. Inspect the page when the streamer’s offline and look for class names or data attributes on the profile image. Try something like:

profile_pic = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img[alt*='profile']")))

Or use Twitch’s typical class structure:

profile_pic = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[data-a-target*='avatar']")))

The exact selector depends on how Twitch’s HTML is structured right now. Best bet is using dev tools to copy the full CSS selector path for the profile image when offline - Twitch changes their DOM pretty regularly.