How to use ACTIONS class in Jmeter-webdriver.plugin. - Webdriver Sampler.?

2.9k views Asked by At

Working on Jmeter-WebDriver.plugin. Webdriver Sampler.

I am facing a issue with focus, (Cursor is not moved to editable field) while executing a script. So wants to click on that field by Webdriver's Action.

Here is my code :-

var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var wait = new support_ui.WebDriverWait(WDS.browser, 5000)

WDS.sampleResult.sampleStart()
WDS.browser.get('')
WDS.browser.findElement(pkg.By.id('vxcvc')).sendKeys(['nabsnba'])
WDS.browser.findElement(pkg.By.id('CenPxcv_Password')).sendKeys(['fraxdy5'])

WDS.browser.findElement(pkg.By.cssSelector('.mdl-button__ripple-container')).click()


var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var wait = new support_ui.WebDriverWait(WDS.browser, 50000)


WDS.browser.findElement(pkg.By.id('sdsdsdsd')).sendKeys(['sdfdsf'])    // On this  line  getting error 

Error is :-

2016/12/19 18:54:59 ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: unknown error: cannot focus element
  (Session info: chrome=55.0.2883.87)
  (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 31 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'ETPUN-DT009', ip: '192.168.254.13', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e71dd9ad489a2728c289cde547a77105
1

There are 1 answers

0
Dmitri T On BEST ANSWER

It should be something like:

var actions = new org.openqa.selenium.interactions.Actions(WDS.browser)
// do what you need with actions

Full code demonstrating doubleclick on JMeter logo at JMeter Plugins project main page:

WDS.sampleResult.sampleStart()
WDS.browser.get('http://jmeter-plugins.org')

var jmeterLogo = WDS.browser.findElement(org.openqa.selenium.By.xpath("//img[@alt='Apache JMeter']"))

var actions = new org.openqa.selenium.interactions.Actions(WDS.browser)
actions.moveToElement(jmeterLogo).doubleClick().perform()

WDS.sampleResult.sampleEnd()

See The WebDriver Sampler: Your Top 10 Questions Answered article for more information on JMeter and Selenium integration