'How can I get the number of selected item from an inputDialog which contains a comboBox?
Using this part of code I am getting a list of urls and add them as items into the comboBox of an JOptionPane InputDialog:
def getURL() {
WebDriver wDriver = DriverFactory.getWebDriver()
List<WebElement> wElements = wDriver.findElements(By.xpath('//a'))
List<String> hrefs = []
for (WebElement wElement : wElements) {
String href = wElement.getAttribute("href")
if (href != null) {
hrefs.add(href)
}
}
String message_result = JOptionPane.showInputDialog(null, "Message Text", "Message Title", JOptionPane.INFORMATION_MESSAGE, null, hrefs.toArray(), hrefs.toArray()[0])
println('You have select: ' + message_result)
}
As it is now, it will print the selected url as string:
You have select: https://www.google.com
What I want to do is to print the selected url as the number of selected item. For example, instead of You have select: https://www.google.com, I want to get this:
You have select: 4
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
