![](/img/trans.png)
[英]Webdriver CSS locators suddenly stopped working on IE11, while xpath locators do work
[英]XPath/CSS/Locators to select title radio button option using WebDriver
是否存在以下问题的代码? 我无法编写正确的XPath或CSS为下面的代码选择标题“ MRS”。 我正在使用下面的代码,但无法执行它。
。driver.findElement(By.xpath( “// DIV [@值= 'MRS']”))点击();
<div class="question-controls clearfix">
<div class="question-group ">
<label class="off">Mr</label>
<input type="radio" name="title" value="MR" class="ui-helper-hidden-accessible">
<label class="off">Mrs</label>
<input type="radio" name="title" value="MRS" class="ui-helper-hidden-accessible">
<label class="on">Miss</label>
<input type="radio" name="title" value="MISS" class="ui-helper-hidden-accessible">
<label class="off">Ms</label>
<input type="radio" name="title" value="MS" class="ui-helper-hidden-accessible">
<label class="off">Dr</label>
<input type="radio" name="title" value="DR" class="ui-helper-hidden-accessible">
<label class="off">Rev</label>
<input type="radio" name="title" value="REV" class="ui-helper-hidden-accessible">
<input type="text" maxlength="20" style="display:none" name="otherTitle" value="" placeholder="Other title:" id="otherTitle">
</div>
</div>
参考链接:
//div[@class='question-group']/input[@type='radio'][@value='MRS']
如果上述xpath不起作用,请查看您要查找的元素是否在任何iframe中,在这种情况下,请先切换到该框架,然后尝试选择此单选按钮。
driver.switchTo().frame(driver.findElement(By.xpath("iframexpath here")));
按照您提供的HTML要求 ,当元素具有clearfix
类时,在与标题MRS相关的元素上调用click()
,您需要诱导WebDriverWait使所需的元素可单击,并且可以使用以下解决方案:
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='question-controls clearfix']/div[@class='question-group']//label[contains(.,'Mrs')]//following::input[1]"))).click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.