1
votes

I am trying to enter a value into a textfield then Tab to the next field (which also enters the value). The Keys.TAB method does not seem to be working.

My code is as follows:

var Keys = JavaImporter(org.openqa.selenium.Keys)

var input = WDS.browser.findElement(pkg.By.xpath('xpath_to_input'))
input.sendKeys('value')
input.sendKeys(Keys.TAB)

I am getting the following error:

sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method org.openqa.selenium.remote.RemoteWebElement.sendKeys(string). <Unknown source>

Thank you for your help. I have tried all sorts of things and it will not work.

2

2 Answers

2
votes

In addition to what ekuusela suggests there are 2 more options:

  1. Use \t escape sequence like:

    input.sendKeys('value\t');
    
  2. Use java.awt.Robot approach as follows:

    input.sendKeys('value')
    var robot = new java.awt.Robot()
    var keyEvent = java.awt.event.KeyEvent
    robot.keyPress(keyEvent.VK_TAB)
    robot.keyRelease(keyEvent.VK_TAB)
    

Remember that "Robot" approach simulates native key and mouse event on the machine where it is executed so if you use remote webdriver instance it won't play.

For more WebDriver Sampler tips and tricks see The WebDriver Sampler: Your Top 10 Questions Answered guide.

1
votes

If you use Java 6 you must pass the string in an array, like this:

var input = WDS.browser.findElement(pkg.By.xpath('xpath_to_input'))
input.sendKeys(['value'])
input.sendKeys([Keys.TAB])

http://jmeter-plugins.org/wiki/WebDriverSampler/