0

I want to automate stablediffusionweb using python selenium but it is giving an error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"input.scroll-hide.svelte-2xzfnp"}
  (Session info: chrome=111.0.5563.149)

My code is:



from selenium import webdriver
from selenium.webdriver.chrome.options import Options 
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By


chrome_options = Options()
#chrome_options.add_argument("--headless")
driver = webdriver.Chrome()


start_url=("https://stablediffusionweb.com/#demo")
driver.get(start_url)
driver.implicitly_wait(10)
input_box = driver.find_element(by=By.CSS_SELECTOR, value="input.scroll-hide.svelte-2xzfnp")
input_box.send_keys("A cute cat wearing a hat")
input_box.send_keys(Keys.ENTER)


I am trying to automate stablediffusionweb using python selenium lib but it is not working

Martin
  • 158
  • 1
  • 3
  • 13
mrithul e
  • 23
  • 4

1 Answers1

0

The problem is with you trying to get the element before it's loaded.
You should always use explicit waits to make sure that elements are there before you try to interact with them, like this:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

wait = WebDriverWait(driver, 30)

input_box_selector = 'input.scroll-hide.svelte-2xzfnp'
input_box = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, input_box_selector)))

Also i would recommend you to use another selector, since the class 'svelte-2xzfnp' will most likely be regenerated everytime the site gets rebuilt, breaking your script. A better selector would be:

input[placeholder='Enter your prompt']

or just

input.scroll-hide
Romek
  • 284
  • 2
  • 10