![](/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.