Can´t find inner text of an element

10 posts, 0 answers
  1. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 18 Dec 2012 Link to this post

    Hi,

    I´ve got a big problem by getting the inner text of an element. I spent a whole day in trying and letting this in theory simple thing drive me crazy..

    <span id="messageText">That´s the text i want to get...</span>

    I want to assert this text but always get an empty string. This is my current code:
    var frame = browser.WaitForElement(new HtmlFindExpression("id=rightIFrame"), 10000, false);
    var span = frame.Find.ByExpression<HtmlSpan>(
    "id=rightIFrame");
    span.Wait.ForExists();
    Assert.AreEqual(
    "That´s the text i want to get...", span.TextContent);

    Result:
    Expected string length x but was 0. Strings differ at index 0.
      Expected: "That´s the text i want to get.."
      But was:  <string.Empty>
      -----------^

    I also tried InnerText but it doesn´t change anything, now I just don´t know what to do and hope you can help me.

    (Edit: I also already tried Thread.Sleep(), even though it surely hadn´t been a clean and good solution, just to see if the text maybe hasn´t loaded yet, but not even that did change anything..)

    Thanks
    Kind regards

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 18 Dec 2012 Link to this post

    Hello Silvio,

    According to the HTML code you have provided to me it is not clear is that span in some frame with ID "rightIFrame"? You can find a frame in our framework via this code:

    ArtOfTest.WebAii.Core.Browser frame = ActiveBrowser.Frames.ById("rightIFrame");

    In all cases the ID you are using for locating the span element in your code is not correct. The ID of the span is "messageText". Try to change it.

    Please try out this slightly different code:

    ArtOfTest.WebAii.Core.Browser frame = ActiveBrowser.Frames.ById("rightIFrame");
    HtmlSpan span = frame.Find.ByExpression<HtmlSpan>("id=messageText");
    span.Wait.ForExists();
    Assert.AreEqual("That´s the text i want to get...", span.TextContent);

    Let me know if this helps.

    Greetings,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 18 Dec 2012 Link to this post

    Oooh sorry..
    I quickly wrote this piece of code here in the forum just to show what I mean. ^^ In fact I use That´s surely not my problem. I also switched to the parent-iframe and interacted with some children without a problem. And I can also find the span, but not the text in it..
    I tried everything and really just don´t know what else to do.

    Edit: I really wonder how I could write such nonsense..^^
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 18 Dec 2012 Link to this post

    Hello Silvio,

    Please try

    Assert.AreEqual("That´s the text i want to get...", span.InnerText);
     
    instead of 

    Assert.AreEqual("That´s the text i want to get...", span.TextContent);

    this will get the text if there is some child element.Kind regards,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 18 Dec 2012 Link to this post

    Thanks for your help!
    Unfortunately I already tried this, without success. I tried everything possible and nothing worked.

    Here are some additional informations (maybe it helps):
    The affected control is a modal popup div with the span in it.
    First i have to change to the contentFrame, click a button and then the popup shows up. I can find the div and I can also find the span, but when I ask it for its text I get an empty string. No matter how long I wait and what I do.

    This is what this popup looks like:

    <div>
      <div>
        <img />
        <span>This is the text</span>
      </div>
      <div>
        <button>
          <span />
        </button>
      </div>
    </div>


    I´ve got no idea what´s the problem and what i could do..


    Edit:
    The next strange thing: I wanted to get the InnerText from all Elements to see if I can find it there. What I got were the StyleSheets.

    This code
    rightFrame.Find.AllElements().ToList().ForEach(e => Console.WriteLine(e.InnerText + "\r\n"));


    had this result
    html,
          body
          {
           
    height: 100%;
           
    margin: 0;
           
    padding: 0;
           
    overflow:hidden;
          }

    html,
          body
          {
           
    height: 100%;
           
    margin: 0;
           
    padding: 0;
           
    overflow:hidden;
          }
  6. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 18 Dec 2012 Link to this post

    Hi Silvio,

    Please double check that you are connecting to this pop up and finding the correct span. There should be no problem to obtain the text if you are able to find the right span. Also you can see its text in the debug mode in the Visual Studio. I recorded a short video as a demonstration.

    In order to help you best please if it is possible provide us with a copy of your project and a direct access to the application or point us to a similar public one. You can also record a short video so we can witness this behavior. Jing is a good free screen recorder.

    All the best,

    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  7. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 18 Dec 2012 Link to this post

    It works!!
    How could i´ve known...

    First I connected to the frame and then I clicked a button in this frame. In fact at this time the browser jumped back to the main document (even though the site didn´t change).

    Thank you very much for your help!

    Kind regards
  8. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 18 Dec 2012 Link to this post

    Hello Silvio,

    I am happy to hear you have solved the issue. 

    If you have any further questions please do not hesitate to contact us.

    Greetings,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  9. Yatindra
    Yatindra avatar
    8 posts
    Member since:
    Apr 2013

    Posted 20 May 2013 Link to this post

    Hi,

    I am also having a similar issue, I have a modal pop-up(not HTML modal) that comes on the screen and takes the precedence. The modal has a div tag inside it and many controls inside the div, so imagine <parent page> <div id="this is a modal"><input type="text" value="abc"/><input type="image" src="" /></div></parent page>. 

    My issue is that I am not able to find the elements, Image,Textbox,etc inside the div, and also not able to find the div tag. Please can you help me with this issue.

    I am using 2012.2.1420.0version of ArtOfTest.WebAii library.
  10. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 21 May 2013 Link to this post

    Hi Yatindra,

    What do you mean by not HTML modal? What kind of pop up it is?

    What code do you use for accessing the element in the pop up?

    Modal Popups require special code and should be handled as demonstrated here.

    In order to help you best please if it is possible provide us with a copy of your project and a direct access to the application or point us to a similar public one. You can also record a short video so we can witness this behavior. Jing is a good free screen recorder.

    Please send us the trace log.

    Hope to hear from you soon.

    Regards,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top