2016-08-05 262 views
1

我在與下面的代碼有問題:蟒蛇硒excpected條件send_keys

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') 

,我發現了以下錯誤:

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

我是新Python的用戶,我希望你對這個問題的幫助。

感謝

HTML的iframe和輸入:

<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> 
+1

框架在http://selenium-python.readthedocs.io/waits.html '看看presence_of_element_located'返回給你'明確的等待',你需要解析使用等待元素。 –

+0

你可以分享你的HTML框架和輸入以及。 –

+0

我從html中省略了一些代碼,因爲這裏沒有被接受。 –

回答

1

您需要使用until功能從WebDriverWaitexpected_conditions。它也看起來不像字段在iframe。試試這個

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

順便說一句,切換到你可以這樣做

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

我嘗試這個時遇到TimeoutException。 –

+0

@ErjolBane在哪裏?另外,請添加相關的html。 – Guy

+0

@ErjolBane'frame_to_be_available_and_switch_to_it'應該得到定位器。不是字符串,就像'presence_of_element_located' – Guy