-2

How can I get the text from a simple html tag

<h2>ABCDEF</h2>

using Selenium RC?

I want to match the exact text. If I use isTextPresent() it returns true even if I put selenium.isTextPresent("ABC").

This is in a HTML tag <h2>.

Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
gagan
  • 173
  • 1
  • 3
  • 11
  • I know this doesn't answer your question, but do you have to use RC or can you use WebDriver? From the Selenium home page, "Selenium WebDriver is the successor of Selenium Remote Control which has been officially deprecated..." http://docs.seleniumhq.org/ – JaneGoodall Apr 09 '14 at 23:25

1 Answers1

-1

Then you need to do the following

strText = selenium.getText("//h2")

if strText.equals("ABCDEF")
     System.out.println("TextMatch")
else
     System.out.println("Text Mismatch")
Harshavardhan Konakanchi
  • 4,238
  • 6
  • 36
  • 54
  • 1
    Since the OP tagged the post with [tag:junit], more appropriate would be just: `assertEquals("Text Mismatch", "ABCDEF", selenium.getText("//h2"))` – SiKing Jul 02 '14 at 20:41