1

I am trying to select a specific radio button with the XPath command:

driver.FindElement(By.XPath("//td[contains(@input id,   'SearchTypePatientNameDob')]")).Click();

The list that contains the button I want is as follows:

<tr>
    <td>
    <input id="RadioButtonSearchTypePatientNameDob" type="radio"      value="SearchTypePatientNameDob" name="SearchType">
    <span class="Instructions">Patient Name / Patient Date of Birth</span>
    </td>
</tr>

My command can not find the button to select/click it. Any suggestions would be of great benefit.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Rinktacular
  • 1,116
  • 3
  • 19
  • 45

1 Answers1

2

You need to locate the input element, not the td element:

//input[contains(@id, 'SearchTypePatientNameDob')]

Note that I don't see any legitimate reason why would not you use a simple By.Id locator:

driver.FindElement(By.Id("RadioButtonSearchTypePatientNameDob")).Click();

You may also need to explicitly wait for the element to be present.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thank you for a quick response! I would expect this command to work, however, I continue to get an error saying that it does not exist on the page. – Rinktacular May 26 '15 at 15:57
  • 1
    @Rinktacular alright, there can be multiple reasons. First of all, do you see any iframe/frame elements on the page? Thanks. – alecxe May 26 '15 at 16:01
  • 1
    @Rinktacular I've also added a link to the answer providing the way to wait for element to become present. – alecxe May 26 '15 at 16:03
  • Yes, there is one. I apologize, I am unfamiliar with this type of and didn't know it was important to the original question. It is quite large, but I can post it if it will assist you/myself. – Rinktacular May 26 '15 at 16:06
  • I have been trying to wait for the element to appear with `driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(100));` ..but that was before I knew that – Rinktacular May 26 '15 at 16:08
  • 1
    @Rinktacular yeah, if the element is inside the iframe, in order to locate the element, you need to switch to the `iframe` using `driver.SwitchTo().Frame()`. – alecxe May 26 '15 at 16:09
  • @Rinktacular yeah, so, basically, switch to the iframe and then try to find the element. – alecxe May 26 '15 at 16:11
  • So given the information: `` Am I using the command correctly? `driver.SwitchTo().Frame("");` – Rinktacular May 26 '15 at 16:22
  • 1
    @Rinktacular nope, `driver.SwitchTo().Frame("childFrame");` – alecxe May 26 '15 at 16:30
  • Using that line of code now comes back with an error saying that childFrame can not be found. Any suggestions? – Rinktacular May 26 '15 at 16:35
  • 1
    @Rinktacular is it the only iframe on the page? If yes, you may need to wait for this iframe element to be present in the DOM (follow the link in the answer). Thanks. – alecxe May 26 '15 at 16:37
  • Thank you for all the help, there is more than one iframe and I will work with the link you provided. +1 – Rinktacular May 26 '15 at 16:42
  • 1
    @Rinktacular then, you need to switch to iframes one by one, going from the parent to the child frame. – alecxe May 26 '15 at 16:44