1
votes

I need to use below javascript executor lines for webdriver sampler in Jmeter.

WebElement el1 = driver.findElement(By.xpath("//div/button/span[contains( text(),'View Report')]")); JavascriptExecutor executor1 = (JavascriptExecutor)driver; executor1.executeScript("arguments[0].click()", el1);

I tried to use below lines but getting below error message in logs var btnView = pkg.By.xpath("//div/button/span[contains( text(),'View Report')]"); WDS.browser.executeScript("document.getElementByXpath(arguments[0]).click();", btnView ) Error message: ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Argument is of an illegal type: org.openqa.selenium.By$ByXPath

Is there any way use javascript executor in Webdriver Sampler?

1
Please take a minute to properly format your code as code and format the error message. See the help on formatting if you are unsure on how to do that. - JeffC

1 Answers

3
votes
  1. You don't need this cast to JavascriptExecutor
  2. You don't need this arguments[0].click(); in the JavaScript will be quite enough, there is no need to re-locate the element, moreover document.getElementByXpath is not something supported currently by the document object

So amend your code as follows:

var btnView = WDS.browser.findElement(pkg.By.xpath("//div/button/span[contains( text(),'View Report')]"))
WDS.browser.executeScript("arguments[0].click();", btnView) 

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