doucheng2210
doucheng2210
2015-04-22 20:24
浏览 173
已采纳

使用Webdriver的代码 - 单击具有相同名称/值/类型的按钮

I'm trying to find out how I can use $I->click with codeception for a button that shares the same name/value/type as another button on the same page. Examples are:

<input class="submit_btn uppercase" type="submit" name="go" value="/GO/"> // button I want to click

AND

<input class="submit_btn" type="submit" value="/GO/" name="go"> // button I don't want to click

What syntax should I use to delineate between the two? I've tried many different things including using the CSS locator after the button name like:

$I->click('go', '.uppercase'); // 2nd item is CSS locator

I've also tried:

$I->click('go', '.submit_btn uppercase'); // 2nd item is CSS locator

图片转代码服务由CSDN问答提供 功能建议

我正在试图找出如何使用 $ I-&gt;点击 使用与同一页面上的另一个按钮共享相同名称/值/类型的按钮的代码。 例如:

&lt; input class =“submit_btn uppercase”type =“submit”name =“go”value =“/ GO /”&gt; //按钮我想点击

AND

&lt; input class =“submit_btn”type =“submit” value =“/ GO /”name =“go”&gt; //按钮我不想点击

我应该使用什么语法来描述两者之间的界限? 我尝试了很多不同的东西,包括在按钮名称之后使用CSS定位器,如:

$ I-&gt; click('go','。upperpercase'); //第二项是CSS定位器

我也尝试过:

$ I-&gt; click(' go','。sububmit_btn uppercase'); //第二项是CSS定位器

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douxing8323
    douxing8323 2015-04-23 10:31
    已采纳

    Firstly, I believe you should find a nearest parent tag that has id defined. I'll assume that there is a parent tag that has id="formId" Here is the code to click that element by CSS selector:

    $I->click('#formId > input.submit_btn.uppercase');
    

    There is another way that you could click this element by xpath:

    $I->click('//input[@class="submit_btn uppercase"]');
    
    点赞 评论
  • doujiyan0031
    doujiyan0031 2015-04-22 20:51

    I'm not familiar with codeception, but if it has full CSS selector support (ambiguous to me after a quick look at their docs) you can look at using a :not(s) selector.

    If that's the case, you should be able to use something like:

    $I->click('go', '.submit_btn:not(.uppercase)');
    
    点赞 评论

相关推荐