Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby web表滚动不工作watir webdriver_Ruby_Watir Webdriver - Fatal编程技术网

Ruby web表滚动不工作watir webdriver

Ruby web表滚动不工作watir webdriver,ruby,watir-webdriver,Ruby,Watir Webdriver,我需要滚动网页中的表格,并获得特定的文本。但滚动表格不起作用 我在网页中有一个21行的表格,其中只有10行是可见的。如果我们想看到其余的行,那么我们需要向下滚动。另外,如果我在irb中给出下面的命令来获取长度,那么它只显示10行,但该表中有21行 irb(main):177:0> @browser.div(:class => 'table-container',:index =>1).tables(:class => 'row-table').length => 1

我需要滚动网页中的表格,并获得特定的文本。但滚动表格不起作用

我在网页中有一个21行的表格,其中只有10行是可见的。如果我们想看到其余的行,那么我们需要向下滚动。另外,如果我在irb中给出下面的命令来获取长度,那么它只显示10行,但该表中有21行

irb(main):177:0> @browser.div(:class => 'table-container',:index =>1).tables(:class => 'row-table').length
=> 10
如果我试图获取第19行中的文本,则会显示无法定位元素的错误

我还使用了如下滚动命令,但滚动不起作用:

@browser.div(:class=>'mainContainer2').table(:id => 'row-table').div(:text=>/#{data}/).wd.location_once_scrolled_into_view
当我手动滚动表格一次后在irb窗口中发出上述命令时,只有上述命令起作用


此外,我还尝试迭代并检查表中的每一行,以匹配预期的文本,但在那里,它也只迭代并检查10行可见的行。

您可以尝试一些方法

您可以使用javascript更改表容器的大小:

container = browser.div(:class => 'table-container',:index =>1)
script = "return arguments[0].height = 1000"
browser.execute_script(script, container)
container = browser.div(:class => 'table-container',:index =>1)
script = "return arguments[0].scrollTop -= 10"
browser.execute_script(script, container)
您可以尝试向表容器发送键:

container = browser.div(:class => 'table-container',:index =>1)
container.send_keys :arrow_down
最后,您可以尝试通过javascript滚动元素:

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

如果这个想法不起作用,请提供链接到您的网页或容器的html的一部分。这将有助于创建100%工作的代码。

感谢您的快速响应。