未定义的方法'点击' - Webdriver
问题描述:
我正在学习测试自动化。我在Ruby语言中使用'cucumber','rspec','selenium-web driver'框架。在测试中,我几乎可以执行每一步。自动点击按钮时发生错误。未定义的方法'点击' - Webdriver
Step definitions:
Quando(/^clicar o botão "([^"]*)"$/) do |botaoSave|
# @navegador.find_elements(:xpath, "//*[@id='SAVE']").trigger("click")
@navegador.find_elements(:xpath, "//*[@id='SAVE']").click
end
显示错误消息:
E clicar o botão "SAVE" # features/step_definitions/criarConta.rb:92
undefined method `click' for #<Array:0x00000002847680> (NoMethodError)
./features/step_definitions/criarConta.rb:94:in `/^clicar o botão "([^"]*)"$/'
features/criarConta.feature:30:in `E clicar o botão "SAVE"'
Então a conta será cadastrada corretamente # features/criarConta.feature:31
Failing Scenarios:
cucumber features/criarConta.feature:7 # Cenário: Cadastrando uma conta
1 scenario (1 failed)
23 steps (1 failed, 1 undefined, 21 passed)
答
find_elements
返回一个数组。您需要使用find_element
,当我改变它返回一个元素
@navegador.find_element(:xpath, "//*[@id='SAVE']").click
:@ navegador.find_element(:XPath中,“//*[@id='SAVE']").click 未知错误:元素如果(check_form('EditView'));如果(check_form('EditView'));如果(check_form('EditView' ))SUGAR.ajaxUI.submitForm(_form); return false;“在点(287,20)处不能点击type =“submit”name =“button”value =“Save”id =“SAVE”>。其他元素会收到点击: –
@DavidsonJacob它看起来像实际的按钮覆盖了你的元素试图点击。尝试'@ navegador.find_element(:xpath,“// * [@ title ='Save']”)。点击' – Guy
我改变了代码,但正在显示另一个错误 @ navegador.find_element(:xpath,“/ /*[@title='Save']""点击 未知错误:元素。 –