A Confused Programmer's Blog

This blog is dedicated to C# programming that I happen to do for living – with accent on curious cases and with sincere intent to make the world a better place as a result

Selenium changes format of DateTime attribute

Recently I was assigned a task of writing automated tests for web based application. The testing framework that was chosen was Selenium v2.25. While this tool is quite powerful (for example, it will fail attempted interaction with element if this element is not accessible because it is hidden or currently blocked by another object), I ran into two issues.

The first one is being slowness when it comes to retrieving data. I had a table consisting of ~100 cells. When I attempted reading contents of all cells using matching xpath expression, the process took about two minutes. Looking at Selenium logs, it looks like server produces excessive traffic (something that looks like SOAP message exchange for each element involved) with the browser. Could it be the source of the slowness? Anyway, from looking at forums, I got an impression that the process cannot be currently speed up and the only suggestion is to filter out the unneeded elements at the level of xpath query.

The second issue is rather peculiar and is actually the reason I am writing this post. We have added an attribute to one of the DOM elements containing timestamp including milliseconds, so it looked like:

span id='myspan' timestamp='2013-01-01Z20:45:30.822'

Now, when I used Selenium API to retrieve the value from the object:

driver.FindElementByXPath("//span[@id='myspan']").GetAttribute("timestamp")

I get the value in default timestamp tostring format (without milliseconds). Peek into the source code might give a hint why this happens:

public string GetAttribute(string attributeName)
{
Dictionary parameters = new Dictionary();
parameters.Add("id", this.elementId);
parameters.Add("name", attributeName);
Response commandResponse = this.Execute(DriverCommand.GetElementAttribute, parameters);
string attributeValue = string.Empty;
if (commandResponse.Value == null)
{
return null;
}
attributeValue = commandResponse.Value.ToString();
if (commandResponse.Value is bool)
{
attributeValue = attributeValue.ToLowerInvariant();
}
return attributeValue;
}

As we see, if the attribute is parsed as timestamp and transferred as object to the Selenium server. Then it is converted to string using parameterless tostring method. In conclusion, if you want to read timestamp value in non default format through Selenium, you will have to display it in unparsable format for the Selenium framework (for example, replace dot with comma before the milliseconds).

Comments are closed.

Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Getting rid of Error

Since I upgraded my Windows 8 to Windows 10, I ...

Bypassing EULA step

We are working on automated testing of virtual appliance. This appliance ...

How I got rid of "Ac

OVF is a VMware virtual appliance format which allows you ...

My use-case of Perfo

In my blog I am set on a mission to ...

Connection to VIM AP

I rarely post about the issues I am experiencing in ...

Twitter updates

RSS not configured