如何在 Twitch 頁面上選擇文本框元素?
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')
uj5u.com熱心網友回復:
如果您使用 xpath 并允許使用 webdriver 加載會更好 WebDriverWait
在這里閱讀更多
你應該使用這樣的東西:
WebDriverWait(driver, 20).until(expected_conditions.presence_of_element_located((By.XPATH, "//*[@data-a-target="chat-input"]")))
uj5u.com熱心網友回復:
請使用此 xpath
//textarea[@data-test-selector='chat-input']
代碼試用1:
time.sleep(5)
driver.find_element_by_xpath("//textarea[@data-test-selector='chat-input']").send_keys('hi')
代碼試用2:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[@data-test-selector='chat-input']"))).send_keys('hi')
進口:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/316226.html
