'Python Selenium can´t find a way to write in a form inside iframe tag
I'm trying to write some text to an element which looks like this:

The HTML code looks like this:

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.
Solution 1:[1]
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
bodytag, 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:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
