tags:

views:

122

answers:

3

I've been running selenium tests against a site and on one of the main pages that people use most often the page is 450KB. It's a horribly designed page but that's not really the point. When I'm writing my selenium tests, every time the test needs to locate something on the page by an ID, it takes 30 seconds to find the element. As a result, this is making the tests run incredibly slow.

I'm using iehta as the browser type. It's also an https site.

I'm also using the following for the xpath parser which I've heard is supposed to be faster.

selenium.UseXpathLibrary("javascript-xpath");

If you can think of anything that would make locating these elements faster, any hints or suggestions please let me know. I'm wondering if I need to configure something differently on my system to make the locating of the elements go faster.

A: 

That is an unusually large page, but not unheard of. Are you including the size of your session? Also, if the page employs AJAX, you won't see all of it in the "source".

Is the page valid XHTML? If so you could treat it like an XmlDocument and XPath your way into it.

tsilb
+1  A: 

Xpath and IE with Selenium do take a long time to process. One of the best ways to get round this is to make it find the element a lot quicker is to make the XPath more direct.

For example if an element has a class in its attribute add it to the Xpath query. e.g //div can become //div[@class='classname']

If it has an ID, even if its dynamic try use it. e.g //div[contains(@id,'nondynamicpart_')]

The more direct the xpath the quicker it will be because less items will be returned with each query.

The page size will affect the speed of the querying so making it smaller will make it quicker

AutomatedTester
better yet, hunt from the actual root (if the path is predictable) and avoid the expensive //
annakata
A: 

Location strategy based on XPath might be extremely slow under IE(esp. IE6). In addition to previuos answers, I'd suggest to try .css based location strategy (you can find samples of it in Selenium's documentation).

"the test needs to locate something on the page by an ID" - that's unclear, since locationg by ID should be one of the fastest ways. Why do you use XPath for elements having IDs, why not built-in selenium's features (I'm talking about something like selenium.type("ID", "textToType"))?