【问题标题】:Python Selenium accessing multilevel HTMLPython Selenium 访问多级 HTML
【发布时间】:2016-10-28 19:27:09
【问题描述】:

如何使用 python selenium 模块访问多级 html 文件。示例 html 文件是:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#">
    <head>
        <body style="background: rgb(26, 26, 26)" class="remodal_lock remodal_active">
        <iframe id="ifrBmAuthApi" class="black-bg">
            <!DOCTYPE html>
            <html>
                <head>
                </head>
                <body>  
                <div class="ascendon">
                    <div id="accountManagementDiv" class="container-fluid">
                        <form id="SAMLPOST" method="POST">
                            <div class="validation-summary" cdvalidate="Email"></div>
                            <input id="Email-input" class="form-control stacked-input err" data-prop="Email" maxlength="50" required="" placeholder="Email" type="email">
                            </div>
                        </form>
                    </div>
                </div>
            </body>
        </html>
    </iframe>   
    </body>
</head>

我想访问内部 html file-id : "Email-input"

我尝试以下场景直接访问 id="Email-input" 和 class="form-control stack-input err" 失败。

例如: >>> print driver.find_element_by_id("Email-input").is_displayed()

错误

【问题讨论】:

    标签: python selenium selenium-webdriver


    【解决方案1】:

    我使用 switch_to.frame(帧的 id)解决了它

    browser.switch_to.frame("ifrBmAuthApi")
    

    Browser是Webdriver的变量

    【讨论】:

      猜你喜欢
      • 2011-12-13
      • 2016-05-12
      • 2020-01-12
      • 2020-09-06
      • 2021-06-10
      • 1970-01-01
      • 2021-07-20
      • 2022-01-25
      • 2016-10-20
      相关资源
      最近更新 更多