2017-06-20 28 views
0

我試圖用behat登錄https://testinternal.com/login(內部網站),但我得到以下錯誤。我使用Firefox開發人員來檢查文本字段名稱,字段名稱與用戶名和密碼字段是正確的。任何想法爲什麼失敗?登錄失敗,即使字段名稱正確

13:40:34.128 INFO - 執行:得到:https://testinternal.com]) 13:40:34.249信息 - 完成:得到:https://testinternal.com/logon] 13:40:34.251 INFO - 執行:發現元素:通過。 xpath: //html/.// [self :: input | self :: textarea | self :: select] [not(./@type = 'submit'or ./@type ='image'or ./@type ='hidden')] [(((./@ id = 'username'或./@name ='username')或./@id = //標籤[包含(normalize-space(string(。)),'username')]/@ for)或 ./@placeholder ='用戶名')] | .// label [contains(normalize-space(string(。)), 'username')] //.// [self :: input | self :: textarea | self :: select] [not(./@type ='submit'or ./@type ='image'or ./@type = 'hidden')]])13:40:34.270信息 - 完成:[找到元素:By.xpath: //html/.// [self :: input | self :: textarea | self :: select] [not(./@type = 'submit'or ./@type ='image'or ./@type ='hidden')] [(((./@ id = 'username'或./@name ='username')或./@id = //標籤[包含(normalize-space(string(。)),'username')]/@ for)或 ./@placeholder ='用戶名')] | .// label [contains(normalize-space(string(。)), 'username')] //.// [self :: input | self :: textarea | 自::選擇] [未(./@類型= '提交' 或./@type = '圖像' 或./@type = '隱藏')]]

Feature: Sign in to the website 
    In order to access the administrative interface 
     As a visitor 
     I need to be able to log in to the website 

    @javascript 
     Scenario: Log in with username and password      # features/signin.feature:7 
     Given I am on "/logon"          # Behat\MinkExtension\Context\MinkContext::visit() 
     When I fill in the following:         # Behat\MinkExtension\Context\MinkContext::fillFields() 
      | username | testuser | 
      | password | testpwd | 
      Form field with id|name|label|value "username" not found. 
     And I press "Sign in"           # Behat\MinkExtension\Context\MinkContext::pressButton() 
     Then I should be on "http://testinternal.com"     # Behat\MinkExtension\Context\MinkContext::assertPageAddress() 
     And I should see "My Flows"         # Behat\MinkExtension\Context\MinkContext::assertPageContainsText() 

    2 scenarios (2 failed) 
    10 steps (2 passed, 6 skipped, 2 failed) 

回答

0

我可以從錯誤中查看您要查找的元素是隱藏的。硒不提供與隱藏元素的交互。有兩種方法可以解決這個問題。

方法

  1. 等待元素是可見的。你可以檢查你的元素可見的動作。

  2. 您可以點擊使用JavaScript執行程序。

JavascriptExecutor js =(JavascriptExecutor)driver; js.executeScript(「arguments [0] .click();」,element);

+0

嗨@Monika,是的頁面是基於JavaScript的應用程序。我能夠控制#1方法。對於#2方法,我應該在哪裏放置這個JavaScript執行程序?在behat功能文件? –

+0

看起來像behat,你可以按照第一種方法。請繼續前進,並遵循第一種方法。我通過查看錯誤給出瞭解決方案。我不確定第二點如何在behat中實現,因爲我從未與behat一起工作過。我可以探索並讓你知道。 – Monika

+0

對不起,我有錯字,我無法控制#1,因爲這個應用程序是由開發團隊完成的。我的工作是自動化測試案例 –