Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 Selenium::WebDriver::Error::ElementNotVisibleError使用Watir循环单击按钮时出错_Ruby_Rspec_Watir_Watir Webdriver - Fatal编程技术网

Ruby Selenium::WebDriver::Error::ElementNotVisibleError使用Watir循环单击按钮时出错

Ruby Selenium::WebDriver::Error::ElementNotVisibleError使用Watir循环单击按钮时出错,ruby,rspec,watir,watir-webdriver,Ruby,Rspec,Watir,Watir Webdriver,我试图在循环的基础上单击一个按钮 假设我有以下代码 if ind == 2 export_id = @browser.div(:id => pop_id).div(:class => /actionDropDownItem groupChild nonSelectable/,:title => "Export").id @browser.div(:id => export_id).click else @browser.div(:id => pop_id

我试图在循环的基础上单击一个按钮

假设我有以下代码

if ind == 2
  export_id = @browser.div(:id => pop_id).div(:class => /actionDropDownItem groupChild nonSelectable/,:title => "Export").id
  @browser.div(:id => export_id).click
else
  @browser.div(:id => pop_id).div(:class => /actionDropDownItem groupChild nonSelectable/,:title => "Export").click
end
但它在索引值“2”处显示错误,错误为

Selenium::WebDriver::Error::ElementNotVisibleError:
Element is not currently visible and so may not be interacted with

在这种情况下,有人能帮我吗?

如果您提供正确的html,那就太好了

试试这个,这个对你有用

if ind == 2
  export_id = @browser.div(:id => export_id)
  export_id.click
else
  @browser.div(:id => pop_id).div(:class => /actionDropDownItem groupChild nonSelectable/,:title => "Export").click
end

异常表示元素不可见。您可能需要执行一些其他操作以使其可见-例如将鼠标悬停在下拉菜单上。在很多情况下,在单击元素之前尝试类似sleep 2的方法,结果证明是可行的。尝试告诉Ruby在尝试单击它之前等待一两秒钟。@Daremk我尝试过使用sleep并等待直到出现,但仍然失败,并且它得到的ID也是错误的。您是否尝试过通过xpath查找元素?尝试编写xpath表达式,有一个站点出现了此错误,使用xpath表达式查找元素完成了这项工作。