so I'm fairly new to python but I start to understand how things work together, however for this problem I didn't find any solution.
So my problem is I'm making a simple bot with python that can open Youtube and search for specific keywords, Now I have tried the send.keys
method and it won't work because I want to use special characters that ChromeWebDriver
just can't send due to chromedriver only supports characters in the bmp
Problem!
So then I explored my options 1 using GeckoDriver Firefox instead and yeah it worked! however, I couldn't make Firefox undetected as a bot!
option 2 is using the execute_script
method with ChromeWebDriver it did work at first with Google search, But then I wanted to use it for Youtube and nothing happens.
I run my script browser works youtube page is loaded but nothing happens the script completes the 20s sleep and exists normally but no input has been made in the search bar or any error in my console just nothing!
maybe the element is not loaded? but I put 20sec sleep
after each line of code to make sure the page have enough time to load properly I tried to use Find_by_id | xPath | class_name
still nothing
I tried to check if the element is there before executing the input text line and still nothing
Also, I have tried to .click
the element before doing text input the search bar is highlighted the click worked but still no text and nothing.
As for the characters I'm trying to input into the search bar are like this:
which can't be sent by the send.key
method
My code:
import undetected_chromedriver.v2 as uc
from time import sleep
import jdk
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
if __name__ == '__main__':
driver = uc.Chrome()
driver.get('https://youtube.com')
sleep(20)
driver.execute_script("document.getElementById('search').checked = true;")
print('Searching for Element')
sleep(20)
Elem_nt = driver.find_element(By.XPATH, "/html/body/ytd-app/div/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form")
print('Finding Element Now...')
sleep(20)
driver.find_element(By.XPATH, "/html/body/ytd-app/div/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form").click()
print('Clickling Element Now')
sleep(20)
driver.execute_script("arguments[0].value = 'vid_title';", Elem_nt)
print('input Text Now')
sleep(20)
Any help would be appreciated, also excuse the terms that I use to explain as I'm new to this I just want to explain everything.