【问题标题】:Watir Webdriver - Span text can't be output all values which is blocked by scroll bar Firefox 40Watir Webdriver - Span 文本无法输出所有被滚动条 Firefox 40 阻止的值
【发布时间】:2015-12-02 19:09:42
【问题描述】:
最近我正在升级我的watir-webdriver框架,目前是Watir-wedbriver0.8.0和Firefox 40。完成后,发现span.text无法输出滚动条不可见的部分。
这是一个例子,
这是一个数据网格,它是一个跨度集合。我想循环数据网格中的所有值并输出它们,但最后只输出可以在一个屏幕中查看的值。如果更改windows的解决方案,使滚动条丢失,并且所有值都在一屏查看,则将全部输出。但是class_name可以正常工作。有人对此有解决方案吗?
代码在这里:
table_row_spans = @browser.get_current_frame_span(header_span_id).spans
table_row_spans.each do |table_cell|
puts table_cell.text
puts table_cell.class_name
end
【问题讨论】:
标签:
ruby
firefox
selenium
watir
watir-webdriver
【解决方案1】:
您可以通过列表中最后一个 span 元素的scrolling into view 来解决它:
browser.execute_script('arguments[0].scrollIntoView();', table_row_spans.last)
或者,对每个匹配的元素都这样做:
table_row_spans.each do |table_cell|
browser.execute_script('arguments[0].scrollIntoView();', table_cell)
puts table_cell.text
puts table_cell.class_name
end
【解决方案2】:
试试下面的方法 ;)
以下方法将存在于 div 中的特定元素(例如网格 div id)滚动到视图中。此方法通过移动滚动条将元素移动到视图中。因此,找到特定滚动条所属的 iv_id 很重要。 element_to_scroll_to 是将其位置滚动到视图中的实际对象。
def scoll_div_element_into_view(div_id, element_to_scroll_to)
# Find the x and y coordinate of the element.
wd_point = element_to_scroll_to.wd.location
# Scroll to it.
execute_script('document.getElementById(arguments[0]).scrollTo(arguments[1],arguments[2]);', div_id, wd_point.x, wd_point.y)
end