【发布时间】:2019-04-27 20:36:28
【问题描述】:
我有一个 div,其中包含一个输入,其中包含一个标识符作为 id 和一个标签。使用我的 selenium 方法,我可以轻松地将输入选择为 webElement,但是如何通过 Input WebElement 获取标签 webElement?
<div class="item-selectable small-2 radio-item columns xsmall-12 item-selectable-stacked">
<input id="0-3" name="RatingQuestions[0].Score" type="radio" value="3" checked="">
<label for="0-3">
</label>
</div>
这是 selenium 中选择 webElement 的方法,目前只选择输入而不是标签。
public void RateQuestion(int questionnumber, int rating)
{
string questionid = questionnumber.ToString() + "-" + rating.ToString();
IWebElement RateQuestionElement = this.Driver.FindElement(By.Id(questionid));
RateQuestionElement.Click();
}
问题是只有标签是可点击的,因此我需要从输入字段中选择标签,我该怎么做?
【问题讨论】:
-
你能分享你当前的代码吗?您应该以minimal, complete, verifiable example 的形式提出您的问题
-
我已经添加了我的 selenium 选择器代码
-
@Simon.B 为什么需要从输入字段中选择标签?你的用例是什么?访问
<input>或<label>?
标签: c# selenium selenium-webdriver xpath