I need to print all values of the drop .The values are hidden in inspect element. The Inspect element for the OpenDropDown image and CloseDropDown are not showing the drop list, basically hidden. screenshots are attached
I want to print all the values of drop down using java.
Your help is highly appreciated.
I have written the below code but as i am unable to see the path for listed elements so it’s not incomplete.
List allText = driver.findElements(By.path(“Xpath or any path”));
for ( WebElement element: allText) {
System.out.println(element.getText());
}
If the field doesn’t contain the options prior to opening, then you have no choice but to open it, then locate the options. Sometimes, I’ve seen ways of getting hidden options directly with JavaScript, but only sometimes. Best bet is to open the list first. Once the list is open, an xpath of:
//ul[@id='vs8__listbox']//li
should do the trick (you haven’t shared what the children of your <ul>
look like in your first screenshot, but I assume they are <li>
elements.
Once you have the list of <li>
elements, I would do the following in Java to print the text:
for(WebElement element : elements) {
System.out.println(element.getAttribute("textContent")):
}
(you haven’t shared what the children of your <ul>
look like in your first screenshot, but I assume they are <li>
elements.
The <li>is not visible for the list, as you can see in the screenshot too.
The close condition of dropdown showing the below
<ul id="vs14__listbox" role="listbox" class="" style="display: none; visibility: hidden;"></ul>
In my second screenshot when i expanded the <ul> the dropdown gets close. I tried in debugging mode but even when i press ctr+F8 the drop down gets close.
As `<li>` is not visible so below given xpath is also not working
//ul[@id='vs8__listbox']//li
Any help on this please,?
I see, so when you try to interact with the inspector, the dropdown closes. There’s a trick you can use to handle this. In your HTML, right click on the <body>
tag, then select Break on > subtree modifications:
What this will do is pause your debugger anytime the page changes, so that you can inspect elements in real time as they change.
Thanks @Brandon_Hein. It’s work
1 Like