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 7970729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:28:07+00:00 2026-06-04T07:28:07+00:00

I have this xpath: //*[@id=someId::button] Pressing it shows a dropdown list of values. Now,

  • 0

I have this xpath: //*[@id="someId::button"]

Pressing it shows a dropdown list of values.

Now, I know all the elements in the list have an id like this :

//*[@id="someId--popup::popupItemINDEX"]

, where INDEX is a number from 1 to whatever the number of options are.

I also know the value which I must click.

One question would be: since I will always know the id of the button which generates the dropdown, can I get all the elements in the dropdown with a reusable method? (I need to interact with more than one dropdown)

The way I thought about it is:
get the root of the initial ID, as in:

//*[@id="someId 

then add the rest : --popup::popupItem. I also need to add the index and I thought I could use a try block (in order to get though the exceptions when I give a bigger than expected index) like this:

 for(int index=1;index<someBiggerThanExpectedNumber;index++){
     try{
         WebElement aux= driver.findElement(By.xpath(builtString+index+"\"]"));
         if(aux.getText().equals(myDesiredValue))
             aux.click();
     }catch(Exception e){}
 }

Note that I am using the webdriver api and java.

I would like to know if this would work and if there is an easier way of doing this, given the initial information I have.

EDIT: The way I suggested works, but for an easier solution, the accepted answer should be seen

  • 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-04T07:28:09+00:00Added an answer on June 4, 2026 at 7:28 am

    As a rule of thumb, try to select more elements by one query, if possible. Searching for many elements one-by-one will get seriously slow.

    If I understand your needs well, a good way to do this would be using

    driver.findElement(By.id("someId::button")).click();
    driver.findElement(By.xpath("//*[contains(@id, 'someId--popup::popupItem') " +
        "and text()='" + myDesiredValue + "']"))
        .click();
    

    For more information about XPath, see the spec. It’s surprisingly a very good read if you can skip the crap!

    That finds and clicks an element with text equal to you desired value which contains “someId–popup::popupItem” in its ID.

    List<WebElement> list = driver.findElements(By.xpath("//*[contains(@id, 'someId--popup::popupItem')]"));
    

    That finds all just all elements that contain “someId–popup::popupItem” in their ID. You can then traverse the list and look for your desired element.

    Did you know you can call findElement() on a WebElement to search just it’s children?
    – driver.findElement(By.id("someId")).findElements(By.className("clickable"))

    Without a peek on the underlying HTML, I guess I can’t offer the best approach, but I have some in my head.

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

Sidebar

Related Questions

i have this xpath defined for moxy in a jaxb class @XmlPath(child::*/REG) public List
I use this xpath expression to list all NON TEST items: /Items/Item[State!='TEST']/Name Normally input
I have this xml file and I want to get some values with Xpath.
I have this xPath expression that I'm putting into htmlCleaner: //table[@class='StandardTable']/tbody/tr[position()>1]/td[2]/a/img Now, my issue
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
We have this software that has a webservices component. Now, the administrator of this
I have this XML file, from which I'd like to count the number of
If I have an XPath query like NodeA/NodeB[@WIDTH and not(@WIDTH=20)] | NodeC[@WIDTH and not(@WIDTH=20)]/NodeD
for example, i have this xml <elements> <a> <b>6</b> <b>5</b> <b>6</b> </a> <a> <b>5</b>
I have this xpath query: descendant-or-self::link and this html code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta

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.