title: How to find a webelement that has 'checked' attribute in list of child WebElements through Selenium using Katalon Studio
body: <p>I have radio buttons that when either radio button is selected, it gets a <code>checked</code> attribute.</p>
  
  <p>This is how the HTML looks:</p>
  
  <p><a href="https://i.stack.imgur.com/VExdU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VExdU.png" alt="HTML"></a></p>
  
  <p>My implementation of getting the descendant that has a <code>checked</code> attribute:</p>
  
  <pre><code>public TestObject getCheckedTestObjectFromParent(String parentID){
      WebDriver driver = DriverFactory.getWebDriver()
      WebElement parentWebElement = driver.findElement(By.id(parentID))
  
      List&lt;WebElement&gt; children = parentWebElement.findElements(By.xpath(".//*"))
      println(children.size())
      for(int i = 0; i &lt; children.size(); i++){
          TestObject childTestObject = getTestObjectFromWebElement(children[i])
          if(WebUI.verifyElementHasAttribute(childTestObject, 'checked', 10, FailureHandling.OPTIONAL)){
              return childTestObject
          }
      }
  }
  </code></pre>
  
  <p>This is the helper method that I use for converting a <code>WebElement</code> to a <code>TestObject</code> :</p>
  
  <pre><code>public TestObject getTestObjectFromWebElement(WebElement element) {
          TestObject object = new TestObject()
          object.addProperty("xpath", ConditionType.CONTAINS, getXPathFromElement(element))
          return object
      }
  </code></pre>
  
  <p>Helper for getting <code>xpath</code> from <code>WebElement</code> :</p>
  
  <pre><code>protected String getXPathFromElement(WebElement element) {
          String elementDescription = element.toString();
          return elementDescription.substring(elementDescription.lastIndexOf("-&gt; xpath: ") + 10, elementDescription.lastIndexOf("]"));
      }
  </code></pre>
  
  <p>Am I missing something here or is there something wrong with the <code>WebElement</code> -> <code>TestObject</code> conversion? Also is this possible using only TestObject or only WebElement? If I could get child  <code>TestObjects</code> containing certain attributes from a parent <code>TestObject</code> then I wouldn't need to make a mess using <code>WebElements</code>. </p>
  
  <p><strong>Edit</strong></p>
  
  <p>Another image of the HTML, this time with the first radio button checked. As you can see the second radio button no longer has the 'checked' attribute.</p>
  
  <p><a href="https://i.stack.imgur.com/Mlg6y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mlg6y.png" alt="HTML2"></a></p>