-1

I am trying to access the properties of(Properties are the ones which you can see in the Chrome browser developer tools when you highlight the table control on the browser) table object using the selenium web driver. My requirement here is to access the table properties like rows and childNodes . I am using the below code to get the properties of the table.

var propVlu = tblObj.GetAttribute("baseURI");               
Console.WriteLine(propVlu.ToString());     

The output of the code here is exactly what I want :

 Test Name: TblIterateDemo
 Test Outcome:  Passed
 Result StandardOutput:    
http://testbpp.corum.com.au/main/(S(2zpcwh5e2xp4wfkbkhvxranb))/Customer.aspx

But if I try to access a property which has some tree structure like the below :

var propVlu = tblObj.GetAttribute(@"rows[""0""].baseURI");   
if(propVlu  != null)
{        
  Console.WriteLine(propVlu.ToString()); 
} 
else
{
   Console.WriteLine("Property not found");
}

I am getting an the following output

 Property not found

Can some one please help me accessing these kind of properties belonging to a web control control on the browser. Please find the attachment containing the image.The property rows exists and also is not null when I check that on Chrome browser developer tools properties tab.

Image of my Question Description

cheers, Bharat.

  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – JeffC Dec 09 '16 at 02:03
  • Sorry Jeff how is it even related to NullReferenceException article you have suggested? I would suggest you please go through the entire question including the screenshots even before you post and conclude that as a solution. Re posting as duplicate question is not really helping me when actually its noway related to what I have asked. I have to surf other websites to get the answer for this question and it was disappointing from stackoverflow side. Its just frustrating, the mediators just labeling the question as duplicate with out going through the question. – Bharadwaj Pappu Dec 12 '16 at 01:13
  • There's nothing special about the `NullReferenceException` that you have here vs everyone else's. If you read the accepted answer in the link, you would have seen that. It explains what it is and how to find it. You need to read and understand that answer. – JeffC Dec 12 '16 at 02:06
  • I have read the answer and its not related to this post.Let me re-frame the question. How do you access the properties like rows of table(Please Refer to the screenshot) using selenium webdriver. The question is not why am I getting NullReferenceException.) I hope you got it now. Also check the solution I have provided if that helps. – Bharadwaj Pappu Dec 12 '16 at 03:01

2 Answers2

0

Selenium C#, chrome driver is returning null values for the following attributes. Here rows attribute also returning as null, so obviously you'll get

Object reference not set to an instance of an object issue in your C# code.

Attribue : assignedSlot value : Null value from Selenium
Attribue : attributes value : Null value from Selenium
Attribue : caption value : Null value from Selenium
Attribue : childNodes value : Null value from Selenium
Attribue : children value : Null value from Selenium
Attribue : classList value : Null value from Selenium
Attribue : dataset value : Null value from Selenium
Attribue : draggable value : Null value from Selenium
Attribue : firstChild value : Null value from Selenium
Attribue : firstElementChild value : Null value from Selenium
Attribue : hidden value : Null value from Selenium
Attribue : isContentEditable value : Null value from Selenium
Attribue : lastChild value : Null value from Selenium
Attribue : lastElementChild value : Null value from Selenium
Attribue : nextElementSibling value : Null value from Selenium
Attribue : nextSibling value : Null value from Selenium
Attribue : nodeValue value : Null value from Selenium
Attribue : offsetParent value : Null value from Selenium
Attribue : ownerDocument value : Null value from Selenium
Attribue : parentElement value : Null value from Selenium
Attribue : parentNode value : Null value from Selenium
Attribue : prefix value : Null value from Selenium
Attribue : previousElementSibling value : Null value from Selenium
Attribue : previousSibling value : Null value from Selenium
Attribue : rows value : Null value from Selenium
Attribue : shadowRoot value : Null value from Selenium
Attribue : tBodies value : Null value from Selenium
Attribue : tFoot value : Null value from Selenium
Attribue : tHead value : Null value from Selenium



List<string> props = File.ReadAllLines(@"C:\Users\muralidharand\Desktop\prop.txt").ToList();
            IWebDriver driver = new ChromeDriver();
            driver.Url = "http://localhost:801/mywebapp/Create?jobid=4";
            driver.Navigate();
            IWebElement atrWF = driver.FindElement(By.Id("tblParticulars"));
            foreach (string prop in props)
            {
                string result = atrWF.GetAttribute(prop);
                if (result == null)
                {
                    result = "Null value from Selenium";
                    File.AppendAllText(@"C:\Users\muralidharand\Desktop\prop_output.txt", "Attribue : " + prop + " value : " + result + Environment.NewLine);
                }
            }

Hope this helps you.

  • so that means I cannot access all the properties of the control. Is there a way I can access all the properties which where displayed in the properties tab of the chrome developer tools window? By the way if you notice my screenshot of the image I attached the value rows attribute displayed in the chrome browser developer tools window is not null like in the examples which you have displayed above. It has a value HTMLCollection[4] and if you expand that property it has more inside it which is exactly whichI want to explore in my code. – Bharadwaj Pappu Dec 09 '16 at 04:33
  • I used very simple code, please chect that. We may need to look into Selenium code, why it is not returining? – Muralidharan Deenathayalan Dec 09 '16 at 06:56
  • Thanks a lot Murali,I have received some good thought after going through your post and finally could solve the issue. – Bharadwaj Pappu Dec 11 '16 at 23:05
0

I finally found the way to solve it,I have done the following to access the rows property of a table object :

var contents = ((IJavaScriptExecutor)drivr).ExecuteScript("return arguments[0].rows.length; ", tblObj);
Console.WriteLine(contents.ToString());

I got some help from this place http://grokbase.com/t/gg/selenium-users/128dp25q60/how-to-get-all-html-attributes-for-a-tag