0

We have 2 radio buttons with almost same attributes and none of the combination of xpath atributes seem to work . Please help. Below is the HTML code added.

radio button 1:

<label class="label_radio r_off"><input kdfid="flowSelection" kdfapp="order" kdfpage="createOrder" type="radio" id="flowSelection" class="orderWithDealId" name="flowSelection" value="false" onclick="javascript:icw.singleEntry.flowSelection('deal');" checked="true" tabindex="1"></label>
<span class="radioTxt">With a Deal ID</span>

radio button 2:

<label class="label_radio r_on"><input kdfid="flowSelectionnew" kdfapp="order" kdfpage="createOrder" type="radio" id="flowSelectionnew" name="flowSelection" class="orderWithNoDealId" value="true" onclick="javascript:icw.singleEntry.flowSelection('noDeal');" tabindex="1"></label>
<span class="radioTxt">Without a Deal ID</span>

Please help.

supputuri
  • 13,644
  • 2
  • 21
  • 39

3 Answers3

0

Check this.

//span[.='Without a Deal ID']/preceding-sibling::label/input

enter image description here

supputuri
  • 13,644
  • 2
  • 21
  • 39
0

No need to use xpath, className should work.

  1. Try By.className("orderWithDealId") for the first radio button and By.className("orderWithNoDealId") for the second element.

    1. If you must use xpath, try "//input[@class='orderWithDealId']" for the first radio button and "//input[@class='orderWithNoDealId']" for the second radio button.

    2. You can also use the @value = true / false for the first and second radio buttons respectively.

0

To click() on the elements you need to use elementToBeClickable() and you can use either of the following Locator Strategies:

  • With a Deal ID radio button using xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='radioTxt' and text()='With a Deal ID']//preceding::label[1]/input"))).click();
    
  • Without a Deal ID radio button using xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='radioTxt' and text()='Without a Deal ID']//preceding::label[1]/input"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352