Python,硒-即使切换后也无法在IFRAME中找到元素

时间:2020-02-13 19:58:32

标签: python selenium iframe

我正在尝试从iframe中的输入字段获取值。我切换到iframe,但程序仍无法找到该元素,因此引发了超时异常。我正在使用Internet Explorer Web驱动程序,但不能使用任何其他驱动程序,因为该网站只能在Internet Explorer中使用。

我使用的代码:

browser = webdriver.Ie()
browser.get('http://www.thewebsite.com')
wait = WebDriverWait(browser, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'Content')))
MRR = wait.until(EC.element_to_be_clickable((By.XPATH, "//INPUT[@id='txtTotalMonthlyCharge']"))).get_attribute('value')

我已经尝试过增加等待时间,并增加ID的位置

HTML:

<iframe id="Content">
<html>
    <head>

    </head>
    <body style="margin-left: 0; margin-top: 0; overflow:hidden">
        <form name="frmServicesTree" method="post" action="ServicesTree.aspx?AccountNo=50084779&amp;pageID=SERVICESTREE" id="frmServicesTree">
    <table>
    <tr>
        <td class="flowLabel" width="140px"><span id="txtTotalMonthlyChargelabel" style="width:95%;height:17px;">Total Monthly Charge</span></td><td class="flowReadOnly"><input name="txtTotalMonthlyCharge" id="txtTotalMonthlyCharge" type="text" readonly="" tabindex="-1" value="JA$11,199.00" style="vertical-align:top;width:100%;" /></td>
    </tr>
    </table> 
    </body>
</iframe>

0 个答案:

没有答案