web table 滚动不工作 watir webdriver
web table scroll is not working watir webdriver
我需要在网页中滚动 table 并获取特定文本。但是滚动 table 不起作用
我在网页中有一个 table,有 21 行,其中只有 10 行 visible.If 我们想查看剩余的行,然后我们需要向下滚动。另外,如果我在 irb 中给出以下命令来获取长度,那么它只显示 10 行,但其中有 21 行 table
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
当我手动滚动 table 一次后,在 irb window 中给出上述命令时,只有上面的命令有效。
我还尝试迭代并检查 table 中的每一行以匹配预期的文本,但它也只迭代并检查可见的 10 行。
有些事情您可以尝试。
您可以使用 javascript:
更改 table 容器的大小
container = browser.div(:class => 'table-container',:index =>1)
script = "return arguments[0].height = 1000"
browser.execute_script(script, container)
您可以尝试将密钥发送到您的 table 容器:
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].scrollTop -= 10"
browser.execute_script(script, container)
如果这个想法行不通,请将 link 提供给您的页面或包含容器的 html 的一部分。这将有助于创建 100% 有效的代码。
我需要在网页中滚动 table 并获取特定文本。但是滚动 table 不起作用
我在网页中有一个 table,有 21 行,其中只有 10 行 visible.If 我们想查看剩余的行,然后我们需要向下滚动。另外,如果我在 irb 中给出以下命令来获取长度,那么它只显示 10 行,但其中有 21 行 table
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
当我手动滚动 table 一次后,在 irb window 中给出上述命令时,只有上面的命令有效。
我还尝试迭代并检查 table 中的每一行以匹配预期的文本,但它也只迭代并检查可见的 10 行。
有些事情您可以尝试。
您可以使用 javascript:
更改 table 容器的大小container = browser.div(:class => 'table-container',:index =>1)
script = "return arguments[0].height = 1000"
browser.execute_script(script, container)
您可以尝试将密钥发送到您的 table 容器:
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].scrollTop -= 10"
browser.execute_script(script, container)
如果这个想法行不通,请将 link 提供给您的页面或包含容器的 html 的一部分。这将有助于创建 100% 有效的代码。