【问题标题】:Codeception select optionCodeception 选择选项
【发布时间】:2017-07-16 18:34:54
【问题描述】:

我正在使用 codeception 来尝试在我的表单中单击、选择选项。问题是,当我尝试选中复选框时,它会选择隐私信息 href 链接,而不是我希望它选择的复选框。

<div class="row">
  <div class="myclass">
    <div class="mb">
      <label class=" custom-checkbox"><input type="checkbox" id="from_accept" name="fform[accept]" class="custom-checkbox__input" value="1">
	<span class="custom-checkbox__text">
         ::before
          "I agree to terms "
	   <a href="[there is a link here]">terms and conditions</a> 
          "and some more text here "
	    <a href="[there is a link here]">privacy info</a>
         "."
        ::after
	</span>
     </label>
    </div>
  </div>
</div>

我尝试过 Xpath 和 CSS 选择器,但没有成功,即使悬停也显示它只是最后一个 href 锚链接。

【问题讨论】:

  • 你能给我们看看你的作品吗?谢谢

标签: selenium automation webdriver codeception


【解决方案1】:

这是您问题的答案:

试试下面的xpath

//div[@class='row']/div[@class='myclass']/div[@class='mb']/label[@class=' custom-checkbox' and @class='custom-checkbox__input']//self::label

注意class=" custom-checkbox"中有一个空格(即空格)

如果这能回答您的问题,请告诉我。

【讨论】:

  • 感谢您的建议,它已经关闭但它继续选择最后一个锚标记...?
  • 我还修改了代码 .. 因为那里有一些 ::before ::after ... 行。不知道这样有没有区别?
  • @toddy 根据更新的 HTML,要实现所需的步骤会有点棘手。如果 URL 是公共 URL,您可以与我们分享吗?同时检查我更新的答案并让我知道状态。谢谢
  • 感谢您的快速响应。可悲的是它不起作用,仍然点击最后一个“a”标签......目前我无法分享 URL。我会继续努力。事实证明这非常棘手。再次感谢:)
猜你喜欢
  • 1970-01-01
  • 2017-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多