Reputation: 302
<input id="lblProductName+Modem promo +default"
class="cmpAvailableSingleSelectProduct-radioButton"
type="radio"
onclick="cmpAvailableSSProductRadioToggleHandler(event, this,'Line_0.DSL.modemcre_s021403', 'false');"
name="defaultLine_0.DSL.modemcre_s021403Modem promo">
The above type is a radio button where the id is based on the next div tag.
<div class="cmpAvailableSingleSelectProduct-lblProductName">Modem promo - 100 </div>
I do know what will be the name (Modem promo - 100) inside the div class. But I'd like to click on the radio button adjacent to that. I will be getting the value of "Modem promo - 100" as a string. I'd like to compare with the text and click on the adjacent radio button.
Please help me on how to write xpath or finding the webElement. Thanks!
Upvotes: 0
Views: 1587
Reputation: 23825
You should try using xpath as below :-
String ValueOfPromo = "Modem promo - 100";
String xpath = "(.//div[contains(.,'" +ValueOfPromo+ "')]/preceding::input)[1]";
driver.findElement(By.xpath(xpath));
Hope it helps..:)
Upvotes: 0