0

I'm struggling to populate a dropdown I can get it to select it but unsure on what to do to select the value:

var TitleField = WDS.browser.findElement(pkg.By.id('Title'))
TitleField.click()
TitleField.sendKeys(['Mr'])

I've seen some articles and it says you have to import a driver:

var driver  = JavaImporter(org.openqa.selenium.support.ui.Select)

Select selectObject = new Select(driver.findElement(By.id(Title)));
selectObject.selectByValue('Mr');

But this stops the whole test from running.

Can someone clarify what I need to do to select the dropdown value using javascript?

Thanks

Tau7
  • 15
  • 8
  • can you explain more on the problem.If possible provide the link to the url or post the html element – Madhan Jul 29 '15 at 16:03

1 Answers1

1

As per Select JavaDoc it should be instantiated as:

Select(WebElement element)

So you're looking into right direction, but implementation is a little bit incorrect. The correct one would be something like:

var element = WDS.browser.findElement(org.openqa.selenium.By.id('Title'))
var select = new org.openqa.selenium.support.ui.Select(element)
select.selectByVisibleText('Mr')

I cannot guarantee that it will work on your environment, just in case find a complete end-to-end demo against Select try-it-yourself at W3Schools below:

WDS.browser.get('http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select')
WDS.browser.switchTo().frame('iframeResult')
var element = WDS.browser.findElement(org.openqa.selenium.By.xpath('//select'))
var select = new org.openqa.selenium.support.ui.Select(element)
select.selectByVisibleText('Opel')

See The WebDriver Sampler: Your Top 10 Questions Answered for more WebDriver Sampler tips and tricks.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133