[英]XPath/CSS/Locators to select title radio button option using WebDriver
Is there any code for below issues? 是否存在以下问题的代码? I am unable to write the correct XPath or CSS to select the title "MRS" for below code.
我无法编写正确的XPath或CSS为下面的代码选择标题“ MRS”。 I am using below code, but unable to execute it.
我正在使用下面的代码,但无法执行它。
driver.findElement(By.xpath("//div[@value='MRS']")).click(); 。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>
link for reference: 参考链接:
https://sqa.stackexchange.com/q/36421/35535 https://sqa.stackexchange.com/q/36421/35535
//div[@class='question-group']/input[@type='radio'][@value='MRS']
如果上述xpath不起作用,请查看您要查找的元素是否在任何iframe中,在这种情况下,请先切换到该框架,然后尝试选择此单选按钮。
driver.switchTo().frame(driver.findElement(By.xpath("iframexpath here")));
As per the HTML you have provided to invoke click()
on the element related to the title MRS as the element is having the clearfix
class, you need to induce WebDriverWait for the desired element to be clickable and you can use the following solution: 按照您提供的HTML要求 ,当元素具有
clearfix
类时,在与标题MRS相关的元素上调用click()
,您需要诱导WebDriverWait使所需的元素可单击,并且可以使用以下解决方案:
xpath
: 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.