2013-11-21 37 views
0

我使用Behat与貂和硒2. 问题是,我有一个元素两次...“设置”。 第一个元素是(例如)<a href="settings.php">Settings</a>,第二个元素是不可见菜单<a href="settings.php">Settings</a>中的快速链接。网站上的多个元素

如何在szenario中选择第二个“Settings”元素?

当前的例子:

Feature: Setting links 
    Check the links 

    Scenario: I check the links for settings 
    Given I am logged in as "user":"name" 
    Given The page is loaded 
    # Now the problem... I have "Settings" twice and i would test both of them 
    When I follow "Settings" 
    And The page is loaded 
    Then The parameter "sid" should match "[0-9]*" 
    And I should see text matching "ID" 
    And I should see text matching "Firstname" 
    And I should see text matching "Surname" 
    And I should see text matching "Street" 
    And I should see text matching "Zip code" 
    And I should see text matching "Country" 

预先感谢您的任何提示! :)

+0

嗯,我会承担一个是可见的,一个也不会,所以检查元件上的'Displayed'财产。 – Arran

+0

嗯,怎么样?我认为你的意思是FeatureContext,对吧? – PatrickB

+0

你的问题是如何编写小黄瓜,如何使用硒,或两者兼而有之? – Louis

回答

0

例如。
如果你有以下的html:

<div class="items ">

<a href="settings.php">Settings</a>

<a href="settings.php">Settings</a>

尝试使用以下步骤:

And I click on ".items a:second-child" element

+0

'当我点击“a [href $ ='settings']:visible”element#Features \ Context \ FeatureContext :: iClickOnTheElement() 伪类“visible”不被支持.' – PatrickB

+0

可能是尝试执行以下步骤: 1)第一步='当我将光标移动到“.items div:second-child”元素时 2)第二步='我点击“type your xpath”element' – ChechoroArtem

+0

1.'/ ** * @Then/^我点击的XPath “(ΔP。*?)” 元素$/ */ 公共职能clickXpath($选择器) {$ 元素= $这个 - > getSession() - > getPage() - > find('xpath',$ selector); $ element-> click(); } 2/** * @Given/^我将光标移动到 “(ΔP。*?)” 元素$/ */ 公共职能iMoveCursorToElement($选择器) {$ 脚本= <<< JS $('{$ selector}')。addClass('hover'); JS; $ this-> getSession() - > executeScript($ script); }' 抱歉的语法 – ChechoroArtem