CanaryTheBird
CanaryTheBird

Reputation: 259

How can I click the "ABOUT" button on a YouTube channel page?

I am trying to click the "ABOUT" button on a YouTube channel page. enter image description here

However, Chrome didn't show the "ABOUT" information after I ran the following code.

! pip install selenium
from selenium import webdriver

! pip install beautifulsoup4
from bs4 import BeautifulSoup

import time
import requests
import random
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('D:\chromedrive\chromedriver.exe')
keyword=['"K_Pop TV"']

for kk in keyword:
    driver.get("http://youtube.com")
    #enter keyword
    driver.find_element_by_name("""search_query""").send_keys(kk)
    #search
    driver.find_element_by_id("search-icon-legacy").click()
    time.sleep(2)
    #click the first channel
    driver.find_element_by_css_selector('div#avatar.style-scope.ytd-channel-renderer').click()
    time.sleep(2)
    #click "ABOUT"
    driver.find_element_by_css_selector('tp-yt-paper-tab.style-scope.ytd-c4-tabbed-header-renderer').click()

Chrome paused on the "HOME" of the page of YouTube channel. It didn't keep going to show the "ABOUT". Please help me.

Upvotes: 0

Views: 140

Answers (2)

Prophet
Prophet

Reputation: 33361

You are using locator that is not unique.
Try this:

driver.find_element_by_xpath('(//div[@class="tab-content style-scope tp-yt-paper-tab"])[last()]').click()

It is unique and not based on text that also can change

Upvotes: 2

cruisepandey
cruisepandey

Reputation: 29362

try with xpath below :

//div[contains(text(),'About')]

and click it like it below :

driver.find_element_by_xpath("//div[contains(text(),'About')]").click()

Upvotes: 0

Related Questions