0

I am tring to get the attribute type="radio" but I'm not sure how to in the selenium webdriver. I tried by using

if(driver.findElement(By.id("userStatusEnable")).getAttribute("type").equals("radio"))

and also by changing the id to x-auto-210

<div id="userStatusEnable" class="x-form-check-wrap x-form-field x-component " role="presentation" style="position: relative;">
<input id="x-auto-210" class=" x-form-radio" type="radio" name="gxt.RadioGroup.5" style="position: relative; left: 0px; top: 4px;" tabindex="0" value="enabled" aria-describedby="x-auto-190" checked="">
<label class="x-form-cb-label" for="x-auto-210" htmlfor="x-auto-210" style="position: relative; left: 1px; top: 3px;">Enable</label>
</div>
2
  • What exactly are you trying to do? Find the element with type="radio", or verify an element found with another selector has type="radio"? Commented Sep 18, 2014 at 18:36
  • Yea im trying to verify that the ID is of type radio. So i have to confirm that there are 2 radio buttons present on the page i am working with right now but im not sure how to get the attribute. Commented Sep 18, 2014 at 19:06

2 Answers 2

1

One possible approach is to use findElements() and an xpath selector to find input tags with a type="radio":

if(driver.findElements(By.xpath("//input[@type='radio']")).size() == 2)
Sign up to request clarification or add additional context in comments.

1 Comment

seems that OP needs to be sure that there are two radios of specific ID, then it would be: if(driver.findElements(By.xpath("//input[@id='x-auto-210'][@type='radio']")).size() == 2)
0

From your question it sounds like you want to find all input elements with the id x-auto-210 and the type radio. You can do that with the following XPath:

"//input[@id='x-auto-210' and @type='radio']"

I've added an explanation of what the XPath expression is doing

  1. The // says we want to search all element
  2. The input means we are only interested in input elements
  3. The [] contains the conditions we want the input to match (namely, that the id is x-auto-210 and the type is radio)

If you use this expression in conjunction with findElements in selenium, you should be able to find the desired elements

if (driver.findElements(By.XPath("//input[@id='x-auto-210' and @type='radio']")).size() == 2) {
    //Do stuff
}

Comments

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.