How do I locate the text input box on Huggingspace using Selenium + Chrome?

Advertisements

I want to locate the text input box on https://huggingface.co/spaces/damo-vilab/modelscope-text-to-video-synthesis
And enter a prompt into it.

I have tried locating via XPATH

# Locate the text input element and enter the prompt
text_input = WebDriverWait(driver, 30).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="prompt-text-input"]/label/input'))
)

# Click the text input element before entering the prompt
text_input.click()
text_input.clear()
text_input.send_keys(video_prompt)


and via CSS Selector:

# Locate the text input element and enter the prompt
text_input = WebDriverWait(driver, 30).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, "#prompt-text-input > label > input"))
)

# Click the text input element before entering the prompt
text_input.click()
text_input.clear()
text_input.send_keys(video_prompt)

RESULT: The program times out, because it’s unable to find the text input element.

I think I have the correct version of the chromedriver, so I don’t think that’s the problem.

>Solution :

Its part on an iframe thats why you are not not able to access it, you need to first switch tot he iframe and then access the input box

Use below code to switch to frame and then enter the data it should work

driver.get("https://huggingface.co/spaces/damo-vilab/modelscope-text-to-video-synthesis")

frame = driver.find_element(By.XPATH, '//iframe[@title="Space app"]')
driver.switch_to.frame(frame)

text_input = WebDriverWait(driver, 30).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="prompt-text-input"]/label/input'))
)

text_input.send_keys("data")

Leave a ReplyCancel reply