1

I have dropdown as pagination and values are dynamic depends on data. Sometimes it can be 1 and if data are more then it can be 10 so I want to get last value of this dropdown in selenium webdriver.

I have checked 3 similar questions here on stack-overflow but not one has satisfied answer to get last option of dropdown using selenium webdriver & Java.

Helping Hands
  • 5,292
  • 9
  • 60
  • 127

2 Answers2

1

Maybe this helps you out : Measure Size

You can measure the size of the dropdown list and take the last one. Hope i understand your problem.

Code Copy and paste:

Select se = new Select(driver.findElement(By.id("select drop down locator")));

List<WebElement> l = se.getOptions();
l.size();
Community
  • 1
  • 1
MrT
  • 594
  • 2
  • 17
0

There are several ways how to get last option text

1) Find the last item with xpath or css selector and get text of it

xpath=//select/option[last()]
css_selector = select option:last-child

2) Use javascript or jquery

driver.execute_script( "return $('select option:last-child').text()")
dmr
  • 526
  • 2
  • 8