0

我正在學習測試自動化。我在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) 

回答

1

find_elements返回一個數組。您需要使用find_element,當我改變它返回一個元素

@navegador.find_element(:xpath, "//*[@id='SAVE']").click 
+0

:@ 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」>。其他元素會收到點擊:

+0

我改變了代碼,但正在顯示另一個錯誤 @ navegador.find_element(:xpath,「/ /*[@title='Save']""點擊 未知錯誤:元素。 –

相關問題