views:

306

answers:

1

So, I was trying out a test case on a website and Selenium registers the events perfectly. Now, if I have to search for a particular class and get the innerHTML of that class, how would I do it assuming that I am using Java as the driving language?

Just to be more clear. I have a class like this:

<h1 class="classname">.....</h1>

I want to get the entire text between those tags.

And finally, if the ids of the buttons on the page are dynamically generated, how would I test the clicking action on them? These button, I presume are using ajax. When I click on the button, Selenium generates this:

//div[@id='c4aef94de622f51859827294']/div/div/div[1]/span[2]/span/span[3]/a

and the actual HTML of the button is this:

<a href="#" bindpoint="forward" class="ButtonForward"/>

Is it even possible to click on the button?

+1  A: 

You could use the getHtmlSource command to get the entire HTML source, and then use something else to parse the HTML in Java and extract the contents of the target element.

You can locate elements without using an ID, for example if this is the only such button on the page you could locate it:

Using CSS locators:

selenium.click("css=a.ButtonForward");

Using XPath locators:

selenium.click("xpath=/descendant::a[@class='ButtonForward']");
Dave Hunt
Thanks for the info... It keep complaining that it is not able to find an element with that name. One thing though is that the class name has a space in it which I am thinking is the problem. The name is like this: class="ForwardButton Button". Any suggestions on that regard?
Legend
Ok never mind... It works with the xpath expression... Thanks a million!
Legend
Just one more question: Is there any way I can actually get the innerHTML of a particular element or do I have to get the entire html and then parse it?
Legend
You're welcome! :)
Dave Hunt
I don't believe Selenium can get the innerHTML itself, but you might be able to do something with the `getEval` command...
Dave Hunt
Thank You again! :) I'll use that to get the job done...
Legend