How do I select the text box element on a twitch page?
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
op = Options()
op.add_argument("user-data-dir=C:\\Users\\bestg\\AppData\\Local\\Google\\Chrome\\bor")
driver = webdriver.Chrome(options=op)
driver.get('https://www.twitch.tv/mizkif')
#trying to click the chat box
chat = driver.find_element_by_id('chat-input')
chat.click()
chat.send_keys('hi')
CodePudding user response:
It would be better if you use the xpath and also allow the webdriver to load by using WebDriverWait
Read more here
You should use something like this:
WebDriverWait(driver, 20).until(expected_conditions.presence_of_element_located((By.XPATH, "//*[@data-a-target="chat-input"]")))
CodePudding user response:
Please use this xpath
//textarea[@data-test-selector='chat-input']
Code trial 1 :
time.sleep(5)
driver.find_element_by_xpath("//textarea[@data-test-selector='chat-input']").send_keys('hi')
Code trial 2 :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[@data-test-selector='chat-input']"))).send_keys('hi')
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC