How do you handle Camera Permission in web , Google chrome?

Hi Katalon Community! :waving_hand:

I’m currently automating a hybrid web app that requires camera access for a selfie flow. I’m facing a few challenges and would love some guidance.

The Flow:

  1. User navigates to a page that requests camera permission
  2. User clicks the selfie button (capture photo)
  3. User confirms and saves the photo

Challenges I’m facing:

  1. Camera Permission Popup — Chrome’s native camera permission dialog appears mid-test and blocks execution. I’ve tried setting Chrome preferences like profile.default_content

    _setting_values.media_stream_camera: 1 and using --use-fake-ui-for-media-stream, but the popup still occasionally appears.

  2. Element Not Found — The selfie button uses dynamic styling (position: absolute, background: red, border-radius: 10px) with no stable ID or class name. XPath like //*[@id='root']/div/div[3]/div/div[1] works inconsistently.

  3. Confirm/Save Button — After the photo is taken, a confirmation button appears but Katalon sometimes fails to detect it, possibly due to render timing.

What I’ve tried:

  • WebUI.waitForElementVisible() with 10s timeout
  • JavaScript executor click as fallback
  • --use-fake-device-for-media-stream Chrome argument

Questions:

  • What is the most reliable way to auto-grant camera permissions in Katalon without the popup blocking the test?
  • How do you handle elements with no stable locator (no ID, no class) in a React app?
  • Any recommended approach for testing camera/selfie flows in a web automation context?

Any help or example scripts would be greatly appreciated! :folded_hands:

Thanks in advance!

I have not worked in this test scenario, but I am eager to know the solution. May be @qurzunta.kaab or @depapp be helpful.

But I guess Chrome camera permission is a browser‑level popup, so the reliable solution will be to start Chrome with pre‑granted permissions to avoid popup blocking

hi @rapiudinsaputra4

set the Chrome capabilities in Project Settings > Desired Capabilities > Web UI > Chrome rather than passing them at runtime. You need both the argument and the preference together. In Desired Capabilities, add:

// Under chromePreferences
profile.default_content_setting_values.media_stream_camera = 1
profile.default_content_setting_values.notifications = 1
profile.content_settings.exceptions.media_stream_camera.'*.per_host' = [setting: 1]

// Under args
--use-fake-ui-for-media-stream
--use-fake-device-for-media-stream

the content_settings.exceptions entry is what actually pre-grants the permission per origin so the popup never fires. The profile.default_content_setting_values alone is not always sufficient in newer Chrome versions.

for the unstable React locators, stop relying on generated XPath indices. Use a relative strategy targeting nearby stable elements or text content. Something like //div[contains(text(), 'Capture')]/ancestor::button or //button[contains(@class, 'selfie')] will survive re-renders better than //*[@id='root']/div/div[3]/div/div[1]. You can also ask your devs to add data-testid attributes to those elements, which is standard practice for React testing.

for the confirm button timing, wrap the wait in a WebUI.waitForElementClickable() instead of just visible, and increase the retry. If it still flakes, add a small WebUI.delay(1) before the wait as the canvas/stream can take a moment to swap out.

Hi! I’m also pretty new to Katalon and ran into something similar :sweat_smile:

Just wanted to ask, are you running this on localhost or HTTPS? I’ve seen that Chrome can behave differently with camera permissions on non-secure origins.

To stabilize your selfie flow in Katalon, apply these three targeted fixes:

1. Kill the Camera Popup (Desired Capabilities)

Don’t handle the popup with code; prevent it from appearing at the browser level. Go to Project > Settings > Desired Capabilities > Web > Chrome and add these arguments:

  • --use-fake-ui-for-media-stream (Auto-grants camera permission)

  • --use-fake-device-for-media-stream (Replaces the camera feed with a test pattern)

2. Fix the “Element Not Found” (Better XPaths)

Stop using absolute paths (the ones with div/div/div). Use Relative XPaths that look for text or partial attributes which are less likely to change than the layout.

Instead of: //*[@id='root']/div/div[3]/div/div[1] Use these logic patterns:

  • By Text: //button[contains(., 'Capture')]

  • By Icon/Class: //button[contains(@class, 'camera')]

  • By Proximity: //label[text()='Take a Selfie']/following-sibling::button

3. Handle Rendering Delays (Enhanced Wait)

React apps often “flicker” the button into existence. Use a Retry Logic combined with a wait:

Groovy

// Wait for the button to be clickable, not just present
WebUI.waitForElementClickable(findTestObject('Your_Confirm_Button'), 10)

// If standard click fails, use JavaScript to force the click
try {
    WebUI.click(findTestObject('Your_Confirm_Button'))
} catch (Exception e) {
    WebUI.executeJavaScript("arguments[0].click();", Arrays.asList(WebUI.findWebElement(findTestObject('Your_Confirm_Button'))))
}


High-Level Advice: The ultimate solution for dynamic React apps is asking your developers to add a data-test-id attribute to buttons. It takes them 5 seconds and makes your automation 100% stable.

Please let us know whether your issue got resolved?

agree
i want to know which one is resolve @rapiudinsaputra4 issue

Chrome camera popup blocks testsauto-grant via args + dynamic React locators.

Chrome Args (Project Settings > Desired Capabilities)

Add: chromeArguments: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream", "--disable-blink-features=IdleDetection"]

100% bypasses permission dialogs—fake media streams ready.

Selfie Button (No ID React)

Object Repo XPath:

//button[contains(@style, 'background: red') and contains(@style, 'border-radius: 10px')]

Or text/parent:

//div[@id='root']//button[contains(@style, 'position: absolute')]

Dynamic Keyword:

@Keyword
void clickSelfieBtn() {
    TestObject btn = new TestObject('selfie')
    btn.addProperty('xpath', ConditionType.EQUALS, "//button[contains(@style, 'red')]")
    WebUI.waitForElementVisible(btn, 10)
    WebUI.click(btn)
}

Confirm Button

MobileElement.waitForElementVisible(confirmBtn, 10)  // Post-photo render

Full flow: Args → Navigate → JS click selfie → Wait → Confirm

I have included this in my tests and working fine with the approach below.

In Katalon Studio, go to

Project > Project Settings > Desired Capabilities > Web UI > Chrome

Add "args" as below

Any recommended approach for testing camera/selfie flows in a web automation context?

In my experience you should keep this flow manual as you cannot always rely on automation for all of your flows.

The test might give you false positive or false negative results.

@rapiudinsaputra4 your issue resolved?

Yes, whose solution worked ,

pls let us know whether you issue got resolved?

OP might be busy

@rapiudinsaputra4 Any updates? Just wanted to check whether it solved, as it will be helpful others who may come across similar issue.