Erjol Bane Erjol Bane - 4 months ago 28
Python Question

python selenium excpected conditions send_keys

i'm having a problem with the following code:

iFrame = EC.frame_to_be_available_and_switch_to_it(("MAIN_IFRAME"))
uscita = EC.presence_of_element_located((By.XPATH, "//input[contains(.,'password')]"))
uscita.send_keys('passwd')


and i'm getting the following error:

AttributeError: 'presence_of_element_located' object has no attribute 'send_keys'


i'm new Python's user and I would like your help on this problem.

Thanks

HTML for iframe and input:

<td style="text-align:center">
<iframe height="350" width="450" name="timb" src="timb.php" style="position: relative;top:0px"></iframe>
</td>
<td>
<div style="position: relative;top:0px">

<form action="mnghlog6.php" method="post" target="timbri">
<input type="hidden" id="esculappio" name="escu" value="0">
<table style="position: relative;top:0px">
</div></td><td><div class="buttons" style="display:inline;text-align: left;">
</div></td></tr><tr><td><div class="buttons" style="display:inline;text-align: left;">
</div></td><td><div class="buttons" style="display:inline;text-align: left;">
</div></td></tr></tbody></table> </div>
</td>
</tr>
<tr>
<td style="text-align:center">Password <input type="password" name="password" id="password" size="30" value=""></td>
</tr>
</tbody></table>
<input type="hidden" name="tipo" value="">
<input type="hidden" name="flag_inizio">
<input type="hidden" name="durata">
</form>
</div>
</td>
</tr>

Guy Guy
Answer

You need to use until function from WebDriverWait with the expected_conditions. It also doesn't looks like the field is in iframe. Try this

wait = WebDriverWait(driver, 10);
uscita = wait.until(EC.presence_of_element_located((By.ID, "password")))
uscita.send_keys('passwd')

By the way, to switch to the frame you can do something like

iFrame = wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME, "timb")))