0

The issue is I have an xml embedded in the page and When I do a pagesource that xml is not present in the resultant String which I get. I am using Java with selenium webdriver 2.40. using IEDriver. I want to read the iframe middle and its content. the xml having oa:Showconsumer id and need to get the exportid and consumer id from the xml.

How can we get the xml into xml structure? Why is pagesource not fectching this details? It will be great if someone can explain how do we read the xml in this html structre. Also there are multiple frames which makes it difficult

I am posting the source

  `<html>
             <head>
         <body style="overflow: hidden;" leftmargin="0" bottommargin="0" topmargin="0" rightmargin="0">
        <table width="100%" cellspacing="0" cellpadding="0">
          <tbody>
           <tr style="height:43px;">
             <tr style="height:25px;">
              <tr>
               <td colspan="2">
                 <iframe id="content" width="100%" scrolling="no" height="138" frameborder="0"       src="content_default.html" marginheight="0" marginwidth="0"    name="content">
             <html>
                <head><body onload="setDirtyOnChangeEvent(true);resizeContent();setHelpFile('4.htm');resizeMenuDiv();">
                 <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                   <tbody>
                     <tr>
                     <td valign="top" bgcolor="E4DbD8">
                      <td rowspan="2">
                      <td style="width: 100%; vertical-align: top;" rowspan="2">
                         <iframe id="ifrm" class="rande" width="100%" scrolling="auto"         height="100%" frameborder="0" src="emma_default.jsp" marginheight="0" marginwidth="0" name="ifrm">
                          <html>
                            <head>
                            <body onunload="onUnLoadTable();" onload="resize();setReadOnly(false);setDirtyOnChangeEvent(true);doFocus();showExtWindow();">
                           <form action="/emma/mmaXmlOutputDetail.do" method="post" name="xmlMessageForm">
                           <input type="hidden" value="" name="status">
                           <input type="hidden" value="" name="editId">
                           <input type="hidden" value="doNothing" name="task">
                           <input type="hidden" value="-1" name="dbKey">
                           <input type="hidden" value="searchXmlMessage.do?task=doBackToSearchPage&formCacheId=searchXmlMessageForm" name="cancelPath">
                           <input type="hidden" value="1300400" name="messageNumber">
                           <input type="hidden" value="" name="recordsFlag">
                           <input type="hidden" value="" name="xmlFlag">
                           <input type="hidden" value="true" name="outputXmlFlag">
                           <input type="hidden" value="" name="preXmlFlag">
                           <table class="layoutTable">
                           <table class="layoutTable">
                           <script type="text/javascript">
                           <span class="errorText">
                           <script type="text/javascript">
                           <input type="hidden" value="true" name="allMessages">
                           <input type="hidden" value="" name="searchFormCacheId">
                            <div id="table_div" class="content_div" style="height: 877px; overflow: auto;">
                             <iframe id="middle" width="100%" height="100%" frameborder="0" src="showXML.do?task=doShowOutputXml&messageNumber=1300400" marginheight="0" marginwidth="0" name="xml">
                              <html>
                              <head>
                               </head>
                              <body>
                             <showconsumer xsi:schemalocation="http://www.ford.com/oagis ../../../Ford/BODs/ShowConsumer.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oa="http://www.openapplications.org/oagis" xmlns="http://www.ford.com/oagis" revision="6.2" environment="Production">
                          </body>
                                <oa:applicationarea>
                                  <oa:sender>
                                  <oa:logicalid>Volvo</oa:logicalid>
                                  <oa:component>CDB</oa:component>
                                  <oa:task>ExportConsumer</oa:task>
                                  <oa:authorizationid>CDB</oa:authorizationid>
                                 </oa:sender>
                                    <oa:creationdatetime>2014-04-25T12:53:49Z</oa:creationdatetime>
                                     <oa:bodid>0A7F110A-545D-D59F-98F2-F03D98F2F03D</oa:bodid>
                                  </oa:applicationarea>
                                 <dataarea>
                                      <oa:show>
                                           <metadata>
                                            <exportid>160574</exportid>
                                           </metadata>
                                             <consumer>
                                          <consumerheader>
                                         <source></source>
                                                DE
                                      <oa:documentid> </oa:documentid>
                                      </consumerheader>
                                     <consumerdetails category="Person">
                                     <id type="ConsumerId">42202199</id>
                                      <id type="GlobalConsumerId">7230010</id>
                                      <vehiclerelation type="Drives">
                                     <startdate>2014-04-15</startdate>
                                    <enddate>
                                   <changecyclemonthly>
                                   <changecyclemileage>
                                 </changecyclemonthly>
                                     </enddate>
                                  </vehiclerelation>
                                   </consumerdetails>
                                   </consumer>
                                   </oa:show>
                                      </dataarea>
                                 </showconsumer>
                               </body>
                               </html>
                              </iframe>
                                </div>
                                     <table>
                                       </form>
                         </body>
                         </html>
                    </iframe>
                  </td>
                 </tr>
                </tbody>
              </table>
             </body>
            </html>
         </iframe>
         </td>
         </tr>
         </tbody>
         </table>
         </body>
         </html> `
Erki M.
  • 5,022
  • 1
  • 48
  • 74
user3541012
  • 1
  • 1
  • 3

1 Answers1

0

You must not rely on getPageSource method. From the docs.

getPageSource

java.lang.String getPageSource()

Get the source of the last loaded page. If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page. Please consult the documentation of the particular driver being used to determine whether the returned text reflects the current state of the page or the text last sent by the web server. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server. Think of it as an artist's impression.

Returns: The source of the current page

Anyway, it is not reading it, because it is inside the iframe. You have to walk down the iframes and then try to read the elements value. Something like (including typos, written from top of my head):

WebElement content = driver.findElement(By.id("content"));
driver.switchTo.frame(content);
WebElement ifrm = driver.findElement(Byid("ifrm"));
driver.switchTo.frame(ifrm);
WebElement middle = driver.findElement(By.id("middle"));
driver.switchTo.frame(middle);
// Ok, got the element, try to get the source:
String middleSource = middle.getAttribute("innerHTML");
Erki M.
  • 5,022
  • 1
  • 48
  • 74
  • Thanks @Erki . This approach worked and I am getting the xml now but the pagesource is not well formed xml. So working on that now – user3541012 Apr 29 '14 at 07:08