2

I am trying to see if there if the comment section is enabled on a YouTube video. if it's not, the program should return to the top again.

def bot1():
    while True:

        #  First search
        driver.get("https://www.youtube.com/results?sp=CAISAggBUBQ%253D&q=" + k1)
        driver.find_element_by_class_name("yt-uix-tile-link").click()
        try:
            WebDriverWait(driver, 15).until(
                EC.presence_of_element_located((By.CLASS_NAME, "comment-simplebox-renderer-collapsed-content"))
            )
        except TimeoutException:
            bot1()

This gives me the error

Traceback (most recent call last):
  File "C:/Users/Admin/Desktop/My Programs/YouTubeTest/YouTubeTest.py", line 98, in <module>
    bot1()
  File "C:/Users/Admin/Desktop/My Programs/YouTubeTest/YouTubeTest.py", line 73, in bot1
    EC.presence_of_element_located((By.CLASS_NAME, "comment-simplebox-renderer-collapsed-content"))
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

I do got this

from selenium.common.exceptions import TimeoutException

I have no idea why this is happening.

1 Answers1

0

First thing, There is no condition for breaking the loop, this is an infinite loop.

selenium.common.exceptions.TimeoutException and normal TimeoutException is different

Jomin
  • 113
  • 2
  • 8