0

I'm trying to select a radio button based on the name of the address. Below I need to select either the span that has the name or the radio button itself. Either way looks like it will select the radio button. I need to do this based on the name within the span class. There are a random amount of spaces before the name of the person so instead of a StartsWith I've been trying to do this with a contains John Doe.

<div data-a-input-name="selectedAddress" class="a-radio">
   <label><input name="selectedAddress" value="113290190603" type="radio">
    <i class="a-icon a-icon-radio"></i>
     <span class="a-label a-radio-label">
         John Doe, Something RD, Some City, State, #####-####, Phone: #####
     </span>
   </label>
</div>

I can't seem to get the correct syntax regardless of all the ways I've tried. Here are some of the syntax I tried:

var Xpath = "//span[contains(@class,'a-label a-radio-label')][contains(text(),'" + shipName + "')]]";

            var radio = driver.FindElement(By.XPath(Xpath));
            radio.Click();

And this:

var Xpath = ".//input[following-sibling::strong[contains(.,'" + shipName + "')]]";
            var radio = driver.FindElement(By.XPath(Xpath));
            radio.Click();

I cannot point to a specific point with XPath because the item I am looking for might not necessarily be in the same ordered location. That is why I need to search for it by name. I also cannot do it by the value of the input as I do not know that information beforehand. I've actually tried many other variances of the two XPATH syntaxes shown above, but those are what I have left now as examples. Thanks for your help.

1
  • Your first XPath contains extra closing square bracket. To validate your second XPath provide with HTML code sample for input node (I don't see strong node in provided HTML) Commented Jan 3, 2018 at 20:17

1 Answer 1

3

You can try below XPath to locate required radio-button by partial text:

"//label[contains(.,'" + shipName + "')]"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.