无法访问selenium中<object>标记内的元素

时间:2017-10-09 10:13:08

标签: java selenium selenium-webdriver

网页包含一个弹出窗口,弹出窗口中有&lt;'object'&gt;,通过对象Popup显示另一个网站内容。在这个站点内容中,我无法使用selenium将数据输入Login字段。 同样请在这里找到整个HTML代码,请帮助我并为此提供可能的解决方案

<div class="documentViewPopUp extrasPopUp" style>
    <span style="kljhgjk ghjkljhg0">
    <div id="popContainer" class="popContainer" align ="center">
        <div class="row">.....</div>
        <div class="row">
            ::before
            <div class="col-md-20 col-xs-20">
                <div id="dc">
                    <object data="http://80.80.80.80/ExternalService?RequestCode=ABCDEF34GH" id="ABCSLinkAppID" 
                        class="col-md-30 col-md-offset-1 col-xs-30" height="800" type="text/html"> Alternative Content </object>
                        #document
                            <!DOCTYPE html> 
                                <html class="robapp-html" lang="en" data-media-queries="enabled">
                                <head>...........</head>
                                <body class="abc widget">
                                <script type="text/javascript">......</script>
                                <div id="load" class="load">...</div>
                                <script type="text/javascript">.....</script>   
                                <script type="text/javascript" src=""></script>
                                <div id="reelFeedBack" class="hide toast-message feedback-wrapper">.....</div>

                                <div id="modelInfo" class="hide toast-message none feedback-wrapper">......</div>
                                <div id="main-container" class="desktop-device module_10003600 gc multi-account" style="height: 800px; top: 0px;">
                                    <div class="gcContainer FL addMinHeight"> 
                                        <!-- head starts here -->
                                    <div class="ada-offscreen adaScreenLoadMsgFL" tabindex="0">.....</div>
                                        <!-- Header -->
                                    <div class="header row collapse headerTitle fixedHeader">.......</div>
                                        <!-- Header ends here -->
                                        <!-- Content body start here -->
                                    <div class="rwWrapper row  full-page  mainBody  contentScroll" style="max-height: 704px; min-height: 554px;">
                                        ::before
                                        <div id="twinnerWrapper"></div>
                                        <div id="messageWrapper" class="small-plus-wrapper"></div>
                                        <!-- -Splash page holder-->
                                        <div id="splashPage" class="mobileContainer"></div>
                                        <!-- Dummy region to aviod error--> 
                                        <div id="leftContent" class="panel card" style="display:none;"></div>
                                        <!-- New theme wrapper -->
                                        <div class="row collapse small-plus-wrapper" id="main-wapper">        
                                            ::before
                                            <!-- Left section holder -->
                                            <div class="full-page  full-view  full-view-bottom small-12" id="left-section">
                                                <div id="rightContent" class="panel card">
                                                    <div id="main-container_panel_0" class="panel sub-panel active">
                                                        <div class="cardContainer">
                                                            <div id="main-container_panel_0_bodyContent" class="bodyContent desktop-device module_10003592 gc">
                                                                <div class="site-form">
                                                                    <div class="mfawrapper-full-view  full-view-bottom ">
                                                                        <div class=" row small-12">....</div>
                                                                        <div class="row collapse">
                                                                            ::before
                                                                            <div class="small-12  columns small-centered medium-8 smallplusbox">    
                                                                                <div class="squareWrapperSmallplus active no-border-for-mobile-only">
                                                                                    <div class="section-title    show-for-smallplus-only " role="heading" aria-level="2">LOG IN TO YOUR ACCOUNT</div>
                                                                                        <div id="thinplusHeader" class="  siteLogoWrapper show-for-medium-down hide-for-medium-only ">.....</div>
                                                                                        <div class="sdhelpText    show-for-medium-down hide-for-medium-only hide-for-smallplus-only ">......</div>
                                                                                        <div class="mobile-wrapper">
                                                                                            <div id="ddcontent">
                                                                                                <div>
                                                                                                    <div class>
                                                                                                        <div class="row collapse  row medium-7 ">.....</div>
                                                                                                        <!-- end of  global error message -->
                                                                                                        <!-- Form display -->
                                                                                                            <form autocomplete="off" class=" row medium-7   with-form-fields ">
                                                                                                                <div class="sdloginForm">
                                                                                                                    <div class="row collapse " id="row_LOGIN">
                                                                                                                        ::before
                                                                                                                        <div class="small-12  column end">....</div>
                                                                                                                        <div class="small-12  column end"> 
                                                                                                                            <input type="text" name="LOGIN" id="UserLOGIN" maxlength="40" class="formField input-error-field  
                                                                                                                            star_field" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" placeholder="Catalog " 
                                                                                                                            aria-label="Catalog " value=""> 
                                                                                                                        </div>

还请在下面找到我的硒代码。

wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("extrasPopUp")));
Sleeper.sleepTightInSeconds(15);
driver.switchTo().frame("ABCSLinkAppID");
driver.findElement(By.id("UserLOGIN")).sendKeys("emma");

// to get # of fields in the Object Content
List<WebElement>fields=driver.findElements(By.tagName("input"));
System.out.println(fields.size());

使用上面的代码,我无法切换到对象内容和 获取错误为“没有找到按名称或ID为ABCSLinkAppID的框架元素”

1 个答案:

答案 0 :(得分:0)

为什么不使用XPath进行元素声明?

//objectx0020data[@id='ABCSLinkAppID']

x0020是XML中的空格代码。使用此而不是仅使用ID。

相关问题