0

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).

svick
10.2k1 gold badge40 silver badges54 bronze badges
asked Jul 17, 2013 at 6:29

1 Answer 1

1

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");
answered Jul 19, 2013 at 20:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.