Reputation: 153
I have Radio button with value as "CREDIT_CARD
" and the text of the radio button as "New
". Now i need to select a radio button which has text "New".
<div>
<input type="radio" onchange="javascript:toggleAdvancedDisplay('pay_detail','CREDIT_CARD');" value="CREDIT_CARD" name="payment_type" style="margin:0; vertical-align: middle;"/>
<span class="value">New</span>
I tried the below xpath, but it doesn't locate the expected element.
/fieldset[1]/div/div/div[2]/input[@value='CREDIT_CARD']/fieldset[1]/div/div/div[2]/span[contains(text(), 'New')]
What is it i am doing wrong here?
Upvotes: 1
Views: 10230
Reputation: 139
Try this. Does this locate the element you're looking for?
xpath = //*[@value="CREDIT_CARD"]/span[contains(.,"New")]
Upvotes: 0
Reputation: 7008
You can try :
xpath = //input[@value='CREDIT_CARD' and following-sibling::span[contains(., 'New')]]
This will get input tag with CREDIT_CARD
as value and whose sibling contains New
as text.
Upvotes: 3
Reputation: 4739
The <span>
element is not a child of the <input>
element, but it is the next sibling. XPath should be:
/fieldset[1]/div/div/div[2]/input[@value='CREDIT_CARD' and following-sibling::span[1] = 'New']
Upvotes: 2