Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9282103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:17:30+00:00 2026-06-18T18:17:30+00:00

I am using Java and Webdriver with TestNG. I have a text box where

  • 0

I am using Java and Webdriver with TestNG. I have a text box where a user enters a medication name and then clicks a Go button. The program then runs a query to RxNorm and returns the Strength and Form of the medication name. The webpage has a div with an id of whatDosage in that div is a list of buttons with the appropriate strength/form for that medication.

My question is, how do I get either the number of elements in that div or a list of the strength/forms displayed to the user? Ultimately, I will be making a call to RxNorm with the same medication name and comparing the results.

I have tried the following:

(1) String resultsWebPage = driver.findElements(By.id("whatDosage")).toString();
System.out.println(resultsWebPage);

(2) int resultsWebPage = driver.findElements(By.id("whatDosage")).size();
System.out.println(resultsWebPage);

The first example simple returns the id. The second only gave me an output of 1. The medication name I am entering returns 11 results into the whatDosage div

The div looks like this:

<div id="whatDosage" class="btn-group btn-group-vertical buttons-radio span12"    role="radiogroup">
    <input id="dosage1" class="hide" type="radio" value="20 MG Enteric Coated Capsule" name="dosage">
    <button class="btn btn-large" rel="dosage1" role="radio" type="button">20 MG Enteric Coated Capsule</button>
    <input id="dosage2" class="hide" type="radio" value="30 MG Enteric Coated Capsule" name="dosage">
    <button class="btn btn-large" rel="dosage2" role="radio" type="button">30 MG Enteric Coated Capsule</button>
    <input id="dosage3" class="hide" type="radio" value="60 MG Enteric Coated Capsule" name="dosage">
    <button class="btn btn-large" rel="dosage3" role="radio" type="button">60 MG Enteric Coated Capsule</button>
</div>

The input elements are hidden with the button elements being what are displayed on screen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:17:31+00:00Added an answer on June 18, 2026 at 6:17 pm

    This could be resolved by changing your element locating strategy.

    I am assuming a skeleton for your webpage to be something as below. Though this may not be accurate, it will give you an idea of the approach to use.

    <div id="whatDosage">
        <div class="strength>Data 1</div>
        <div class="strength>Data 2</div>
        <div class="strength>Data 3</div>
    </div>
    

    When you run your code (2):

    int resultsWebPage = driver.findElements(By.id("whatDosage")).size();
    

    what it does is that it selects the “whatDosage” div and not the child elements which you require. Now since there is one “whatDosage” div, that explains that doing .size() returns 1.

    You should be doing something on the lines of this:

    List<WebElements> results = driver.findElements(By.className("strength"));
    System.out.println(results.size());
    
    for (WebElement result : results){
        System.out.println(result.getText());
    }
    

    This will give you the following output:

    3
    Data 1
    Data 2
    Data 3
    

    You will want to change the strategy to locate the strength/form elements as per your code. Some apporoached are By.id, By.className, By.xpath, etc. and can refer to the selenium docs for Locating UI elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Selenium Java 2.0b3 . I have this code: ... WebDriver driver =
I'm currently using Eclipse with TestNG running selenium webdriver with java. I am using
I have refreshed the browser in WebDriver using java as below code: driver.navigate().refresh(); How
I am using Selenium WebDriver with Java & TestNG framework. I want to use
I have WebDriver and am using Java. In C# with WatiN I was able
I am using WebDriver with java. I want to input some text in a
I am using WebDriver with Java for test automation. I have the following HTML
How to read data of each cell in Selenium WebDriver using Java? I have
I am using Selenium WebDriver in conjunction with java.awt.Robot to better simulate user interaction
I am using Selenium WebDriver(a.k.a. Selenium 2) with Java. For clicking Sign In button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.