MAX GRIMM
MAX GRIMM

Reputation: 111

No such element error from Web Driver sampler in Jmeter while running headless

Context: Through webdriver sample am running a script and it works fine when I run with GUI mode. While running headless mode in Chrome I am getting no such element exception.

UI SCRIPT

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

Error Details:

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

Error Details: enter image description here

Configuration Change: I am using Chrome Driver

enter image description here

This works fine when the headless checkbox is unchecked. How to resolve this ?

Upvotes: 0

Views: 469

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

It might be the case the headless browser has smaller window hence the element you're trying to interact with is not visible in the viewport.

You can try taking a screenshot to see what exactly is displayed

var screenshot = WDS.browser.getScreenshotAs(org.openqa.selenium.OutputType.FILE)
screenshot.renameTo(new java.io.File('screenshot.png'))

also using sleep is some form of a performance anti-pattern, consider switching to Explicit Waits.

More information: The WebDriver Sampler: Your Top 10 Questions Answered

If this is the case - you can set the browser window size to somewhat bigger like:

WDS.browser.manage().window().setSize(new org.openqa.selenium.Dimension(1980, 1024))

Upvotes: 1

Related Questions