.sendKeys方法在WebDriver Sampler JMeter中的问题

huangapple go评论75阅读模式
英文:

.sendKeys method problems in WebDriver Sampler JMeter

问题

I'm making WebDriver Selenium scripts and trying to run them with JMeter.
I have an issue I don't understand. My code will crash at line 17 with this error in JMeter:

ERROR c.g.j.p.w.s.WebDriverSampler: Sourced file: inline evaluation of: import org.openqa.selenium.; import java.time.Duration; WDS.sampleResult.samp . . . '' : Error in method invocation: Method sendKeys( java.lang.String ) not found in class 'org.openqa.selenium.remote.RemoteWebElement' : at Line: 17 : in file: inline evaluation of: import org.openqa.selenium.*; import java.time.Duration; WDS.sampleResult.samp . . . '' : .sendKeys ( "value" ) in inline evaluation of: import org.openqa.selenium.; import java.time.Duration; WDS.sampleResult.samp . . . '' at line number 17

This is my code in WebDriver Sampler in JMeter:

code with .sendKeys method

What is the problem? Am I just blind?

I tried to import org.openqa.selenium.remote.RemoteWebElement directly to the script and I also tried to change syntax because I learned it was necessary to put an Array instead of a String behind .sendKeys method, but it didn't work for me.

I am using apache-jmeter-5.5 and Script Language in WebDriver Sampler is set to java.

英文:

I'm making WebDriver Selenium scripts and trying to run them with JMeter.
I have an issue I don't understand. My code will crash at line 17 with this error in JMeter:

ERROR c.g.j.p.w.s.WebDriverSampler: Sourced file: inline evaluation of: 
import org.openqa.selenium.*; import java.time.Duration;   WDS.sampleResult.samp . . . '' : Error in method invocation: Method sendKeys( java.lang.String ) not found in class'org.openqa.selenium.remote.RemoteWebElement' : at Line: 17 : in file: inline evaluation of: ``import org.openqa.selenium.*; import java.time.Duration;   WDS.sampleResult.samp . . . '' : .sendKeys ( "value" ) 
 in inline evaluation of: ``import org.openqa.selenium.*; import java.time.Duration;   WDS.sampleResult.samp . . . '' at line number 17

This is my code in WebDriver Sampler in JMeter:

code with .sendKeys method

What is the problem? Am I just blind?

I tried to import org.openqa.selenium.remote.RemoteWebElement directly to the script and I also tried to change syntax because I learned it was necessary to put an Array instead of a String behind .sendKeys method, but it didn't work for me.

I am using apache-jmeter-5.5 and Script Language in WebDriver Sampler is set to java.

答案1

得分: 0

你只是违反了JMeter最佳实践,因为JMeter 3.1版本后不推荐使用Beanshell

原因是WebElement.sendKeys()函数期望一个CharSequence,而你尝试传递一个String,Beanshell解释器不喜欢这样做。

将语言切换到groovy,问题将得以解决。有关在JMeter中使用Groovy脚本的更多信息,请参阅Apache Groovy: Groovy用于什么?文章。

英文:

You're just violating JMeter Best Practices, using Beanshell is not recommended since JMeter 3.1

The reason is that WebElement.sendKeys() function expects a CharSequence and you're trying to pass a String there and Beanshell interpreter doesn't like it.

Switch the language to groovy and the issue will go away. See Apache Groovy: What Is Groovy Used For? article for more information on Groovy scripting in JMeter

huangapple
  • 本文由 发表于 2023年2月8日 22:21:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387124.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定