0

I'm trying to write some text to an element which looks like this:

Pic1

The HTML code looks like this:

Pic2

What I'am trying to do is to figure out, how it would be possible to send text in the form via Selenium.

I've tried alot of things but unfortinatly nothing works. Currently this is the code I have at the moment. I choose to use @class as an indicator of the frame as this value doesn´t change everytime the website reloads.

iframeDescription = driver.find_element_by_xpath("//iframe[@class='ifrm']")
driver.switch_to.frame(iframeDescription)
time.sleep(2)
print(iframeDescription)

formInput = driver.find_element(By.CSS_SELECTOR, "html")
formInput.send_keys("a random Text I wish would appear inside this Box")

I would appreciate some advice.

Edit: thanks for the quick answers guys, I don´t have input tho- or am I missing something? I´ve wrote "test" into the form on the website to try and locate it.

Pic3

Sawa
  • 3
  • 2
  • There is more to `html` in formInput. You may expand the `body` and check for the locator stragegy, generally it would have `input` and/or `type="text"` – Anand Gautam Mar 13 '22 at 14:26
  • Does this help? https://stackoverflow.com/a/61145753/2681662 – MSH Mar 13 '22 at 14:34

1 Answers1

0

The element is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.

Note: You can't send a character sequence to the body tag, instead you have to locate the relevant <input> tag to send the text.

  • You can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='Standard']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "body input"))).send_keys("Sawa")
      
    • Using XPATH:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@title='Standard']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//body//input"))).send_keys("Sawa")
      
  • Note : You have to add the following imports :

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

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the quick response. :) So the first part is working pretty well, WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//body//input"))).send_keys("Sawa") this part doesn´t work tho it times out and I guess it can´t workbecause I also don´t have an input in the html, or am I missing something? I´ll edit the main question with an other screenshot. – Sawa Mar 13 '22 at 15:13
  • See the _**Note**_ part ... _You can't send a character sequence to the body tag, instead you have to locate the relevant tag to send the text._ ... – undetected Selenium Mar 13 '22 at 15:15
  • yeah, i just can´t find the tag, I took a screen for you guys to see. Am I really missing it? I think it should be inside html, shouldn´t it? – Sawa Mar 13 '22 at 15:20