Victor Pudeyev
Victor Pudeyev

Reputation: 4539

Why are Selenium tests so slow?

I am writing a scraper that downloads (legally) a bunch of images and I`ve run into an issue. On the relevant pages, after a page is done loading, it just takes too long find elements by css. So for example I think the script hangs up here for like 10 minutes:

@@wait.until do
        find_element_by_css(css_selector)
    end
    @@driver.find_element(:css => css_selector).text

def find_element_by_css(css_string)
    @@wait.until do
        @@driver.find_element(:css => css_string)
    end
end

Where css_selector = "table:nth-child(6) tr:nth-child(2) .view-value" or something like that. Now, this thing would hang literally for 10-20 minutes without doing anything. And if I remove the call to wait, the script will throw a timeout exception.

Any idea on how to fix this? Any help would be appreciated.

Upvotes: 1

Views: 419

Answers (2)

Jonathan Locker
Jonathan Locker

Reputation: 36

Selenium has a bug using css to locate elements in IE. If you switch to using a different browser (such as Firefox) you should see a vast improvement in performance.

Upvotes: 2

Victor Pudeyev
Victor Pudeyev

Reputation: 4539

I think the problem was buggy selenium. I switched to nokogiri and the problem disappeared. Also, there were some errors/inconsistencies with design of my application.

Upvotes: 2

Related Questions