0
votes

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. I am using below code, but unable to execute it.

driver.findElement(By.xpath("//div[@value='MRS']")).click();

<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

2
Am I crazy or is your "link for reference" a link to your question? We need a link to the page. - pguardiario
- I see a login page with no radios. - pguardiario
Need to login to see that page and i am not allowed to provide the login details - Arjun
You probably won't get a good answer then, sorry. - pguardiario

2 Answers

0
votes

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:

  • 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();
    
0
votes
//div[@class='question-group']/input[@type='radio'][@value='MRS']   

If the above xpath doesn't work, please see if this element you are trying to find is inside any iframe, in such case switch to the frame first and then try selecting this radio button.

driver.switchTo().frame(driver.findElement(By.xpath("iframexpath here")));