gpt4 book ai didi

page-object-gem - 使用页面对象 gem 等待大型 SelectList 数组

转载 作者:行者123 更新时间:2023-12-04 07:15:52 27 4
gpt4 key购买 nike

我正在尝试在动态加载的 SelectList 元素中选择一个项目。

我像这样使用 wait_until:

select_list(:oem, :id => 'oem_1')

def wait_for_oem(oem_name)
self.oem_element.wait_until(20) do
self.oem_options.include? oem_name
end
end

当我的列表只有几个项目时,这非常有用。不幸的是,我的列表有时有 3000 项。发生这种情况时,上述等待需要几分钟才能返回(即使列表只需要几秒钟来填充)。

我也试过:

def wait_for_oem(oem_name)
self.oem_element.wait_until(20) do
self.oem_options.length > 1
end
end

这也好不到哪里去,我可以放入一个 sleep 5 来解决这个问题,但我宁愿避免这种情况。

您能否建议性能更好的等待选项?

最佳答案

我认为最大的成本是检索所有 3000 个选项,这是页面对象 gem 在调用 oem_options 时所做的。通过直接定位该特定选项,您应该会获得性能提升。

似乎没有办法直接在页面对象 gem 中定位选项。因此,您需要直接访问底层的 selenium/watir 方法。

在 Watir-Webdriver 中:

def wait_for_oem(oem_name)
self.oem_element.wait_until(20) do
self.oem_element.element.option(:text => oem_name).exists?
end
end

在 Selenium-Webdriver 中:

def wait_for_oem(oem_name)
self.oem_element.wait_until(20) do
begin
self.oem_element.element.find_element(:xpath => "./option[text()=#{oem_name}]")
rescue
false
end
end
end

使用上述方法检查一个有3000个选项的选择列表,将时间从86秒减少到0.25秒。

关于page-object-gem - 使用页面对象 gem 等待大型 SelectList 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21995363/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com