上下文:通过webdriver示例,我运行了一个脚本,当我在GUI模式下运行时,它工作正常。当在Chrome中运行headless模式时,我没有得到这样的元素异常。
用户界面脚本
WDS.sampleResult.sampleStart()
WDS.browser.get('https://sprnt-app05.perceptive.cloud/sprint04-webimpact');
java.lang.Thread.sleep(10000);
WDS.browser.findElement(org.openqa.selenium.By.id("details-button")).click();
java.lang.Thread.sleep(8000);
WDS.browser.findElement(org.openqa.selenium.By.id("proceed-link")).click();
java.lang.Thread.sleep(8000);
WDS.browser.findElement(org.openqa.selenium.By.id("i0116")).sendKeys("UserName");
java.lang.Thread.sleep(5000);
WDS.browser.findElement(org.openqa.selenium.By.id("idSIButton9")).click();
java.lang.Thread.sleep(5000);
WDS.browser.findElement(org.openqa.selenium.By.id("i0118")).sendKeys("Password");
java.lang.Thread.sleep(5000);
WDS.browser.findElement(org.openqa.selenium.By.id("idSIButton9")).click();
java.lang.Thread.sleep(5000);
WDS.browser.findElement(org.openqa.selenium.By.id("idSIButton9")).click();
java.lang.Thread.sleep(5000);
错误详细信息:
2022-05-24 10:51:19,474 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2022-05-24 10:51:19,474 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2022-05-24 10:51:19,475 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2022-05-24 10:51:19,777 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2022-05-24 10:51:19,777 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2022-05-24 10:51:19,777 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2022-05-24 10:51:19,777 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2022-05-24 10:51:19,784 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2022-05-24 10:51:19,784 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2022-05-24 10:51:19,784 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2022-05-24 10:51:36,164 ERROR c.g.j.p.w.s.WebDriverSampler: no such element: Unable to locate element: {"method":"css selector","selector":"#details\-button"}
(Session info: headless chrome=101.0.4951.67)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'L507574', ip: '192.168.0.130', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 101.0.4951.67, chrome: {chromedriverVersion: 101.0.4951.41 (93c720db8323..., userDataDir: <dir>}, goog:chromeOptions: {debuggerAddress: localhost:57816}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(system), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 38f606e9e44d882027555b6544d319b7
***Element info: {Using=id, value=details-button}
2022-05-24 10:51:36,169 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2022-05-24 10:51:36,169 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2022-05-24 10:51:36,784 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2022-05-24 10:51:36,784 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)
错误详细信息:
配置变更:我使用的是Chrome驱动程序
当没有选中headless复选框时,此操作正常。如何解决此问题?
1条答案
按热度按时间flmtquvp1#
这可能是因为无头浏览器的窗口较小,因此您尝试与之交互的元素在视口中不可见。
你可以试着截图看看到底显示了什么
使用sleep也是某种形式的性能反模式,请考虑切换到显式等待。
更多信息:The WebDriver Sampler: Your Top 10 Questions Answered
如果是这种情况,您可以将浏览器窗口大小设置为稍大一些,如: