I'm trying to use python and selenium to select a specific radio button out of a few that live within a web page. Luckily, the radio button that I want to select does have specific text associated, which should make it easier for me to select. Unfortunately, I'm missing something since all attempts have errored out. Below is the HTML code, what i've tried, and what i'm trying to achieve.
HTML
<div data-a-input-name="slotsRadioGroup" class="a-radio a-radio-fancy slotButtonRadio"><label><input type="radio" name="slotsRadioGroup" value="" autocomplete="off"><i class="a-icon a-icon-radio"></i><span class="a-label a-radio-label">
<span class="slotRadioLabel">
5PM - 7PM
</span>
<div class="a-row">
<span class="a-size-small slot-button-micro-copy preselected-visible">
Soonest available time with all items.
</span>
</div>
</span></label></div>
</div></div>
The radio button I need to select will always have the text "Soonest available..." present.
What I've tried
I've tried different variations of xpath code to attempt to select this based on the text. My last attempt was:
driver.find_element_by_xpath("//input[@type='radio']and following-sibling::span[contains(., 'Soonest available')").click()
Which results in the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//input[@type='radio']and following-sibling::span[contains(., 'Soonest available')' is not a valid XPath expression.
Expected Result What I want is to be able to select the specific radio button based on the above text being present.