1

I'm having trouble trying to figure out how 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:

<tr id="eG9Pg10" class="yw-selector-listitem z-listitem z-listitem-selected">
<td id="eG9Ph10" class="yw-selector-listcell z-listcell">
<div id="eG9Ph10-cave" class="z-listcell-content">
<span id="eG9Pg10-cm" class="z-listitem-checkable z-listitem-radio">
<i class="z-listitem-icon z-icon-radio"></i></span>&nbsp;Store Front Access Backoffice Role</div></td><td id="eG9Pi10" class="yw-selector-listcell z-listcell"> <div id="eG9Pi10-cave" class="z-listcell-content">&nbsp;</div> 

The ids keep changing each time the page is loaded.

I've tried the following to no avail:

driver.FindElementByXPath("//button[@class='z-focus-a']").Click
obj.FindElementByCss("button.z-focus-a[type='button']").Click

This is how the Macro starts off...

Dim obj As New ChromeDriver
obj.Start "chrome", "   "
obj.Get "https://sh.com/backoffice"

1 Answer 1

1

To click on the radio button you can use either of the following Locator Strategies:

  • xpath:

    driver.FindElementByXPath("//td[@class='yw-selector-listcell z-listcell']/div[@class='z-listcell-content' and contains(@id, '-cave')][contains(., 'Store Front Access Backoffice Role')]/span[@class='z-listitem-checkable z-listitem-radio' and contains(@id, '-cm')]").Click
    

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

Sign up to request clarification or add additional context in comments.

2 Comments

Hi DebanjanB, the code works! Thank you kindly. It selects the first radio button in a list of 5. But how do I need select the 5th one in the list. Each of the elements seem to have the same HTML (except for the dynamic ID) as shown above in this question. The text, however is different. It says "Store Front Access Backoffice Role". Is there any way to index these radio buttons using the cssSelector or xpath?
@DWP Checkout the updated answer and let me know the status

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.