Search code examples
rubyseleniumselenium-webdriverpage-object-gem

How to Speed up Ruby Page Object .visible? or exists? Checks


I am using the Page Object Ruby gem to test web pages, and have run into some small performance issues. I have the need to check that elements exist on the current page, but experience long wait times, sometimes in the tens of seconds, with my current method of using .visible? or .exsits?. This performance issue is happening when the element in question does not actually exist on the page.

The html is fairly convoluted so providing an example is difficult, but here is the basic format of the table the code should be looking for:

<body>
  <div>
  <div>
  <div>
  ...
  <table>
    <tbody>
      <tr>
        <td>
          <a href = "#" onclick="return url_here"
        </td>
        <td class= "no wrap">Active<
        <td class= "no wrap">06/15/2016</td>
        <td class= "no wrap">06/15/2016</td>
      </tr>
      <tr>
      <tr>
     </tbody>
    <tfoot>...</tfoot>
  </table>
...

I set the element like so:

table(:attributes_tbody, :xpath => "//*[@id='Form:agrAttributesTable']/tbody")

Then use this code to check whether this table is present on the page:

if attributes_tbody_element.visible?
  attributes_tbody_element.each do |row|
    if row[1].text == to_title_case(attribute)
      p 'EXPECTED ATTRIBUTE EXISTS'
    end
  end
end

The first if check is what takes the most time. I do realize these methods have a lot to sort through, but I am wondering if there is a way to narrow down what is being searched through to speed up these checks? The page in this case is fairly small and generated using JSF, if that helps.

Any help is appreciated!


Solution

  • My guess is that it's related to an implicit wait that you have set on your script(s). Implicit wait will wait the prescribed time until the element appears every time you search for an element. So, if you have a lot of elements that you are looking for or checking visibility, etc. that are missing, you will have a lot of delays. I would suggest you turn off implicit wait and add explicit waits where needed, e.g. WebDriverWait.

    See the Selenium docs for more info on Explicit and Implicit waits.