I need the program to select a message entry element, enter the data and send it.
Here is the beginning of my program. After launching chrome, I go manually to YouTube and turn on some stream with a chat.
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import undetected_chromedriver as uc
chrome_options = Options()
chrome_options.add_argument('--allow-profiles-outside-user-dir')
chrome_options.add_argument('--enable-profile-shortcut-manager')
chrome_options.add_argument(r'user-data-dir=.\User')
chrome_options.add_argument('--profile-directory=Profile 3')
driver = uc.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
x = int(input())
...
After that, I run the program further, and it should find the chat frame (because I read that there are frames on the pages, and selenium only works with the top one, so you need to select the chat frame, because it has it). But the frame is not located, and after viewing the code I could not find any more names, ids, etc. of the frame.
this is one of the options:
pis = driver.find_element(By.XPATH, '//*[@id="content-pages"]')
print(pis)
driver.switch_to.frame(pis)
an example of an html page can be found on any YouTube stream
>Solution :
You need use xpath of iframe itself, not the xpath of element contaning iframe.
So try using
pis = driver.find_element(By.XPATH, '//*[@id="chatframe"]')
You can include iframe tag instead of *, since we are searching iframe, '//iframe[@id="chatframe"]'