Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# 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
enter image description here

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading