rubywatir-webdriver

web table scroll is not working watir webdriver


I need to scroll the table in webpage and get the particular text. But scrolling table is not working

I have a table in webpage with 21 rows where only 10 rows are visible.If we want to see remaining rows then we need to scroll down. Also if i give below command in irb to get the length then it shows 10 rows only but there are 21 rows in that table

irb(main):177:0> @browser.div(:class => 'table-container',:index =>1).tables(:class => 'row-table').length
=> 10

If i tried to get the text in row 19, then it shows error unable to locate element.

Also i have used scroll command as below but scroll is not working:

@browser.div(:class=>'mainContainer2').table(:id => 'row-table').div(:text=>/#{data}/).wd.location_once_scrolled_into_view

When i give the above command in irb window after i manually scrolled the table once then only above command is working.

Also i have tried to iterate and check each row in a table to match the expected text but there also it iterates and checks only 10 rows which are visible.


Solution

  • There are some things you could try.

    You could change the size of your table container using javascript:

    container = browser.div(:class => 'table-container',:index =>1)
    script = "return arguments[0].height = 1000"
    browser.execute_script(script, container)
    

    You could try to send keys to your table container:

    container = browser.div(:class => 'table-container',:index =>1)
    container.send_keys :arrow_down
    

    Finally you could try to scroll element by javascript:

    container = browser.div(:class => 'table-container',:index =>1)
    script = "return arguments[0].scrollTop -= 10"
    browser.execute_script(script, container)
    

    If this ideas will not work please provide link to your page or part of the html with the container. It will help to create code that will 100% work.