Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to develop a selenium application (using c# win forms). So, while the application starts, the users will enter an app name in the text box. I have many fields such as cost, validity etc corresponding to each app.

Example webpage:

description  appname  cost  validity  xyzattribute
--------------------------------------------------
some desc     app1     10      30     someattribute

I want selenium to search the entire page for that given app name and if it finds any, I want selenium to retrieve all the attributes (cost, validity) and store those in a variable. How can I achieve this?

Please note that none of these fields have a unique attribute (such as name/id/any other).

share|improve this question
add comment

1 Answer

If I were you, I would take advantage of Seliniums ability to run and get results from arbitrary javascript commands. Let's assume you have a structure something like this:

<table id="mytable">
    <tr>
       <th>description</th>
       <th>appname</th>
    <tr>
    <tr>
       <td>description 1</td>
       <td>appname 1</td>
    <tr>
    <tr>
       <td>description 2</td>
       <td>appname 2</td>
    <tr>
<table>

To get the the description column value on the second row, you could run this javascript code:

var secondDescription = document.getElementById("mytable").rows[1].children[0].innerHtml

In C#, you first create an instance of IJavascriptExecutor (http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/html/M_OpenQA_Selenium_IJavaScriptExecutor_ExecuteScript.htm):

IWebDriver driver = new FirefoxDriver(); //or whatever
IJavascriptExecutor jsDriver = (IJavaScriptExecutor) driver;

Then to get a value in C#, you simply run the javascript command:

string secondDescription = jsDriver.ExecuteScript("document.getElementById(\"mytable\").rows[1].children[0].innerHtml");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.