【问题标题】:Need generic xpath/css_selectro for following html code [duplicate]需要通用 xpath/css_selectro 用于以下 html 代码 [重复]
【发布时间】:2016-12-12 10:42:34
【问题描述】:

以下是我需要通用 xpath pr css_selector 的 html 代码

<fieldset>
<legend>Forged Email:</legend>
<p class="custom-err-pos-handle">
<input id="domainforging" class="required custom-err-pos valid"  name="forgedemailoption" value="f" aria-required="true" type="checkbox">
<label for="domainforging" style="width:auto" title="Checks that the envelope from domain matches the emails from domain">Envelope Domain Forging</label>
<br>
<input id="replytoheader" class="required custom-err-pos" name="forgedemailoption" value="r" type="checkbox">
<label for="replytoheader" style="width:auto" title="Checks that the domain of the reply-to address matches the envelope from domain">Reply-to Domain Forging</label>
<br>
<input id="headerdomain" class="required custom-err-pos" name="forgedemailoption" value="h" type="checkbox">
<label for="headerdomain" style="width:auto" title="Checks to see if the email From domain has been forged">Header Domain Forging</label>
</p>
</fieldset>

需要传递值“信封域伪造”或“回复域伪造”或“标题域伪造”。

【问题讨论】:

  • I need generic xpath pr css_selector 是为了什么??标签还是输入??

标签: python xpath selenium-webdriver


【解决方案1】:

如果您使用的是 JAVA,则创建一个字符串类型的定位器,如下所示:-

private String locatorName = //label[text()='%s'];

像这样使用上面的

public void passValueMethod(String value){

WebElement 元素 = driver.findElement(By.xpath(String.format(locatorName,value)));

}

每次调用方法 passValueMethod 的参数不同时,都会动态传递给定位器。

【讨论】:

  • 感谢 Shubham,它有效。
【解决方案2】:

如果你想使用文本节点来识别元素,那么你可能需要这个XPath

text = "Envelope Domain Forging"
'//input/label[text()="%s"]' % text

【讨论】:

  • 这不起作用:(
猜你喜欢
  • 2017-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-06
  • 1970-01-01
相关资源
最近更新 更多