在的Watir按钮元素元素不可见错误 [英] Element not visible error for button element in Watir

查看:288
本文介绍了在的Watir按钮元素元素不可见错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Watir为应用程序进行自动测试,并试图一旦我选择选择列表选项,点击提交按钮,并填补了form.However单击按钮时,它抛出元素未找到错误

I'm using watir to perform automated testing for an application and trying to click on a submit button once I select options for select list and fill up the form.However on clicking the button, it throws element not found error

HTML片段的按钮标记

The html snippet for button tag

<button type="submit" class="md-primary md-raised md-button md-default-
theme" ng-transclude=""><span class="ng-binding 
ng-scope">Submit</span><div style="" class="md-ripple-container">
</div>   
</button>

在Ruby脚本

require "watir"
require "watir-webdriver"
browser =  Watir::Browser.new :firefox
browser.goto 'https://54.69.254.137/webui#/landing'
browser.driver.manage.window.maximize
browser.button(:class =>'sign-in md-button md-default-theme').click
browser.text_field(:id =>'input_001').set('abcadmin@example.com')
browser.text_field(:id =>'input_002').set('password')
browser.button(:class =>'md-primary md-raised md-button md-default-  
theme').click
browser.input(:id =>'input_002').when_present.click
browser.element(aria_label:'What do you want to do?').when_present.click
browser.element(:id =>'select_option_00G').when_present.click
browser.element(aria_label:'About what?').when_present.click
browser.element(:id =>'select_option_00P').when_present.click
browser.textarea(:id =>'input_00N').when_present.set('Discuss about 
javascript and later test the application??')
browser.button(:class =>'md-primary md-raised md-button md-default-   
theme').click

这引发以下错误

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

我试图用

browser.button(:class =>'md-primary md-raised md-button md-default-    
theme').when_present.click

,但它会抛出超时error.Not能够纠正错误.Plz帮助!

,but it will throw time out error.Not able to rectify the error .Plz help !!

推荐答案

元素不可见的装置,该元件被发现,但是隐藏或以这样的方式,一个真正的用户将不能够直接点击按钮遮蔽

Element not visible means that the element was found, but is either hidden or obscured in such a way that a real user would not be able to click the button directly.

该错误的两个潜在的原因,一个是别的东西涵盖了你想要的元素。另一种是有,在DOM匹配多个元素都和选择中的一(除非你给的指数值,将的Watir把它找到的第一个)是不可见的。

Two potential causes for that error, one is that something else covers the element you want. The other is that there are more than one element that matches in the dom, and the one being selected (unless you give an index value, watir will take the first one it finds) is not visible.

快速的方法,以确定是哪种情况,是先获取匹配的元素..通过插入一个看跌到脚本权之前,尝试点击按钮(在两行可读性)易<中/计数p>

The fast way to determine which is the case is to first get a count of matching elements.. that is easy by inserting a puts into your script right before it tries to click the button (on two lines for readability)

buttons_found = browser.buttons(:class =>'md-primary md-raised md-button md-default-theme').size
puts "I found #{buttons_found} matching buttons"

如果返回1之外任何东西,那么有可能你选择一个隐藏按钮。也许看,而不是由具有的Watir看看一个容器元素里面,或者找到标识你想要的按钮,一个更独特的方式来选择它。

If that returns anything other than 1, then potentially you are selecting a hidden button. Maybe look instead to select it by having watir look inside a container element, or find a more unique way to identify the button you want.

请注意,使用类组合可以有点脆自类通常用于驱动CSS格式。可以创建两个问题,一个是与相同格式的任何按钮将可能有类相同的组合,如果视觉设计改变类也可以改变例如,如果一个以上的被发现,那么你可以尝试选择按钮通过它的文字,如:

Note that using class combinations can be a bit brittle since classes are often used to drive CSS formatting. That can create two problems, one is that any button with the same formatting will likely have the same combination of classes and if the visual design changes the classes can also change For example if more than one was found, then you could try selecting the button by it's text, such as:

browser.button(:text 'Submit').click

如果只有一个单一的元素中,然后看看是否其他一些因素可能会掩盖你想要的,并尝试点击该网址。

If there is only a single element found, then look to see if some other element might be masking the one you want, and try clicking on that instead.

这篇关于在的Watir按钮元素元素不可见错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆