英文:
.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:
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:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论