gpt4 book ai didi

java - 如何在 Jmeter-webdriver.plugin 中使用 ACTIONS 类。 - Webdriver 采样器。?

转载 作者:行者123 更新时间:2023-12-01 09:06:24 27 4
gpt4 key购买 nike

正在开发 Jmeter-WebDriver.plugin。 Webdriver 采样器。

我在执行脚本时遇到焦点问题(光标未移动到可编辑字段)。因此想要通过 Webdriver 的 Action 单击该字段。

这是我的代码:-

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

错误是:-

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

最佳答案

应该是这样的:

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

演示双击 JMeter Logo 的完整代码 JMeter Plugins项目主页:

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()

参见The WebDriver Sampler: Your Top 10 Questions Answered有关 JMeter 和 Selenium 集成的更多信息的文章

关于java - 如何在 Jmeter-webdriver.plugin 中使用 ACTIONS 类。 - Webdriver 采样器。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41238771/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com