1

I'm struggling once more trying to select a radio button in Chrome (v 75.0.3770.100) using Selenium Basic ChromeDriver (v 75.0.3770.140) in Excel (2013) VBE. Here's the HTML:

<div class=radio-wrap>
<input id="shipToSelect" type="radio" class="radio" 
name="soldToShipToselection" value="SH" ng-click="radioClicked($event)">
<label for="shipToSelect" class="radio-label">
<i></i>
<span>Ship-to</span>
</label>
</div>

I've tried unsuccessfully with the below:

obj.FindElementByCss("div.radio-wrap>input.radio[id$='radio']").Click
obj.FindElementByName("soldToShipToselection").Click
obj.FindElementById("shipToSelect").Click
obj.FindElementByXPath("//div[@class='radio-wrap']/input[.,(@id,'shipToSelect')]").Click
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
DWP
  • 105
  • 1
  • 11

2 Answers2

1

Try the following Xpath to click on radio button.Use Explicit wait before interacting the element.

obj.FindElementByXPath("//div[@class='radio-wrap']/input[@id='shipToSelect']").Click
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • this worked, i had to switchtonextwindow first since the previous line opened a new Chrome tab. Thanks! – DWP Jul 16 '19 at 14:30
1

To click on the radio button associated with the text as Ship-to you can use either of the following Locator Strategies:

  • cssSelector:

    driver.FindElementByCss("label[for='shipToSelect']").Click
    
  • xpath:

    driver.FindElementByXPath("//label[@for='shipToSelect']").Click
    

Note: As it is a JavaScript enabled element you need to induce a waiter for the element to be clickable


Update

As an alternative, you can try either of the folloing Locator Strategies:

  • cssSelector:

    driver.FindElementByCss("input.radio#shipToSelect[name='soldToShipToselection']").Click
    
  • xpath:

    driver.FindElementByXPath("//input[@class='radio' and @id='shipToSelect'][@name='soldToShipToselection']").Click
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • even after waiting till the Chrome isn't busy, it still throws a Run-time error 7: NoSuchElementError Element not found for Css=label[for='shipToSelect'] is there any way to use cssSelector or xpath to click on this element? since it's the actual radio button when inspecting – DWP Jul 16 '19 at 11:07
  • Doesn't the locators in my answer helps you when used along with wait? – undetected Selenium Jul 16 '19 at 11:10
  • Run-time error 7: NoSuchElementError Element not found for Css=label[for='shipToSelect'] – DWP Jul 16 '19 at 11:12
  • `NoSuchElementError` of coarse you need to wait as the element is dynamic element. – undetected Selenium Jul 16 '19 at 11:13
  • yes but even when in the VBE debug mode and Chrome window is completely idle but still throws an error when executing the line – DWP Jul 16 '19 at 11:16
  • the radio buttons are within li and ul tags, not sure if this has to do with it – DWP Jul 16 '19 at 11:25
  • Checkout the answer update and let me know the status. – undetected Selenium Jul 16 '19 at 12:37
  • Hi DebanjanB my bad seems the preceding code opened a new tab in the chrome where these elements are located. Just got to learn how to switch between tabs first (there should be some old posts on this) then those selector strategies should work :) – DWP Jul 16 '19 at 13:56
  • 1
    After I used switchtonextwindow then the solutions provided worked, thank you so much! – DWP Jul 16 '19 at 14:27