Search code examples
jmeterperformance-testing

JMeter WebDriver - Unable to identify an element


I have a Sampler as below:

import org.openqa.selenium.*
import org.openqa.selenium.support.ui.*
import java.time.*

def user = WDS.browser.findElement(By.id('loginUserName'))
user.sendKeys('adminstafftest1')

def pass = WDS.browser.findElement(By.id('loginPassword'))
pass.sendKeys('STuser1225')

def login = WDS.browser.findElement(By.id('loginSubmit'))
def wait = new WebDriverWait(WDS.browser, Duration.ofSeconds(300))
WDS.sampleResult.sampleStart()
login.click()
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector('main-
body.application-unavailable')))
WDS.sampleResult.sampleEnd()

Once the login button is clicked, it needs to wait for the setting button to appear. Then, click on it.

However, am unable to make the script work as expected. i.e. After the login button is clicked, my script just times out throwing an error.

Attaching the screenshot.

Settings Button with its inspect window

I tried with

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector('main-body.application-unavailable')))

and

wait.until(ExpectedConditions.elementToBeClickable(By.id('settingsButton')))

But they don't make a difference. Am I missing something here?

Please help. Thanks for your support.

Regards,


Solution

  • Your By.id('settingsButton') selector is fine, the reasons Selenium cannot find it could be in:

    1. The element is in iframe. In this case you will need to call WebDriver.switchTo() function first
    2. Thet element is in Shadow DOM. In this case you need to first find the relevant ShadowRoot node and then find the element relative to the shadow DOM subtree

    If you need comprehensive help you need to provide the page source, better in full as we cannot guess the reason by looking into partial screenshot. The page source can be obtained either using browser developer tools or by invoking WebDriver.getPageSource() function