How to click on "Allow cookies"?

Hi Team,

In my app, I am trying to automate the registering process through Facebook.
when I click on “Continue with Facebook” in my emulator/simulator, this is the first screen I get

Though I am able to inspect the elements present here and the xpath for "Allow only essential cookies" is //*[@id="u_0_l_vY"] , I cannot able to click on it. Below is the error:

[0-1] 2022-06-16 11:49:26.604  INFO  [src/pageObjects/  switchContextInApp] Switched to WEBVIEW_chrome 
[0-1] 2022-06-16T11:49:26.605Z INFO webdriver: COMMAND findElement("xpath", "//*[@id="u_0_l_vY"]")
[0-1] 2022-06-16T11:49:26.605Z INFO webdriver: [POST] http://localhost:4723/session/7a31aaa3-cee2-4c6b-a50a-321ce34de556/element
[0-1] 2022-06-16T11:49:26.605Z INFO webdriver: DATA { using: 'xpath', value: '//*[@id="u_0_l_vY"]' }
[0-1] 2022-06-16T11:49:26.674Z INFO webdriver: RESULT {
[0-1]   error: 'no such element',
[0-1]   message: 'no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="u_0_l_vY"]"}\n' +
[0-1]     '  (Session info: chrome=91.0.4472.114)\n' +
[0-1]     '  (Driver info: chromedriver=91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch-heads/[email protected]{#1462}),platform=Mac OS X 12.4.0 arm64)',
[0-1]   stacktrace: 'NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="u_0_l_vY"]"}\n' +
[0-1]     '  (Session info: chrome=91.0.4472.114)\n' +
[0-1]     '  (Driver info: chromedriver=91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch-heads/[email protected]{#1462}),platform=Mac OS X 12.4.0 arm64)\n' +
[0-1]     '    at errorFromMJSONWPStatusCode (/Users/integration-tests/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:764:12)\n' +
[0-1]     '    at ProxyRequestError.getActualError (/Users/integration-tests/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:661:14)\n' +
[0-1]     '    at asyncHandler (/Users/integration-tests/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:373:25)'
[0-1] }

Can someone please suggest what can be done to achieve this test step?

Pretty sure that that control is obfuscated intentionally to prevent clicking on it via automation, have you looked around to see what selenium users do to get around this? That hard coded string looks like a recipe for disaster. Have you tried stitching to a different context in the driver?

I looked around what selenium users but did not able to find the right content which can solve my problem.
I also tried to switch context to NATIVE_APP to confirm whether I can click through driver but then also I am getting the error.

    await switchContextInApp('NATIVE_APP');
    const button = await driver.findElement('id', 'Only allow essential cookies');
    const ELEMENT = 'ELEMENT';
    await driver.elementClick(button[ELEMENT]);

1 Like

I’ve not done any Mobile browser control myself. We have a native app so it’s been pretty simple life for me . My app opens a browser, but it’s just a help page, in my case, so I have never tried to control it.
I just know this was super hard to do in selenium/desktop when I did try a year ago and I ended up working around it using a pre saved profile.

I confirmed with my developer. That screen is a part of browser only meaning webview_chrome so there must be something. Can’t we access the element through some other process or can we suppress the cookie page somewhere because I see it opens up on the front of my login page.

@Aleksei Do you have any inputs to solve this problem?

I solved this now. Solution:
const cookie = await browser.findElement(‘css selector’, “[title*=‘Only allow essential cookies’]”);
await driver.elementClick(cookie[‘ELEMENT’]);