开发者

Why are Selenium tests so slow?

开发者 https://www.devze.com 2023-04-04 13:35 出处:网络
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 take开发者_运维技巧s too long find elements b

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 take开发者_运维技巧s 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消