selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters

I am able to launch application. i.e splacescreen
when loginActivity apperas it have two pop for assing permission . i am able to perfoem click using python script . but when plan loginscreen appear it gives me this error
image
button = driver.find_elements_by_class_name(“android.widget.Button”)

Can you paste your Python test script here?

from appium import webdriver
import time
import os

PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(file), p))
desired_caps = {}
desired_caps[‘platformName’] = ‘Android’
#desired_caps[‘appiumVersion’] = ‘1.4.16.1’
#desired_caps[‘platformVersion’] = ‘4.2’
desired_caps[‘deviceName’] = ‘520377bf4269b355’
desired_caps[‘noReset’] = True
#desired_caps[‘app’] = PATH(‘xxx.apk’);
desired_caps[‘appPackage’] = ‘com.xxx’
desired_caps[‘appActivity’] = ‘com.xxx.setup.SplashScreen’
driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)

Test Actions here…

driver.implicitly_wait(15)

button = driver.find_elements_by_class_name(“android.widget.Button”)
button[1].click();

button1 = driver.find_elements_by_class_name(“android.widget.Button”)
button1[1].click();

time.sleep(30)

button2=driver.find_elements_by_class_name(“android.widget.TextView”)
print button2

driver.quit()

button2 print [ ] null array

Assuming you are trying to click on the ‘Login’ button, can you try this?

button2 = driver.find_element_by_xpath('//android.widget.Button[@text = "LOGIN"]')
print button2

If you want to click on the Login button:

button2 = driver.find_element_by_xpath('//android.widget.Button[@text = "LOGIN"]')
button2.click()

appium terminal shows
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: [“xpath”,“//andr
oid.widget.Button[@text = "LOGIN"]”,“ff49d83b-635f-4073-8731-3717fca178d1”]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class
name, accessibility id, -android uiautomator
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class
name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 15000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:
“find”,“params”:{“strategy”:“xpath”,“selector”:“//android.widget.Button[@text =
"LOGIN"]”,“context”:“”,“multiple”:false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:
“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:“//android.widg
et.Button[@text = "LOGIN"]”,“context”:“”,“multiple”:false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘//android.widget.But
ton[@text = “LOGIN”]’ using ‘XPATH’ with the contextId: ‘’ multiple: false

its not going ahead

************when loginActivity launch appium shows

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Cle
aring Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘android.widget.Butto
n’ using ‘CLASS_NAME’ with the contextId: ‘’ multiple: true
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=andro
id.widget.Button]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelect
or[CLASS=android.widget.Button]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSe
lector[CLASS=android.widget.Button, INSTANCE=0]

can you click on the ‘Login’ button in your uiautomator tool and share a screenshot.

hi
i am able to run after change android device having M version.
previos version was N

now i am able to sendkey to username and password . but keyboard hide login button .
not able to click on login.
====Please Help======

driver.find_element_by_id(“com.***:id/editTextUsername”).clear()
driver.find_element_by_id(“com***:id/editTextUsername”).send_keys(‘harsha’)
driver.find_element_by_id(“com.***:id/editTextPwd”).clear()
driver.find_element_by_id(“com.***:id/editTextPwd”).send_keys(‘Pass@123’)
driver.hide_keyboard()

driver.find_element_by_id(“com.***:id/activity_login”).click()

oh that’s great. For click login button does appium says element not found?

no.
there is no error.
But why it is not working on andorid N?
i have latest appium version

add this to your desired capabilities

automationName: 'uiautomator2'

Thanks . working on both devices.
desired_caps[‘automationName’] = ‘uiautomator2’
install uiatomator2 and set JAVA_HOME

I am not able to access webview element using uiautomator2.
i have added webview in android screen
it is possible in default uiatomator
Please help

@Venkatesh_Akula

Hey, tried several ways to find my element, error still shows up.

  1. From the below list , tried all locator strategy, but no help.

#elu = driver.find_element_by_xpath("//*[contains(@text, ‘Baddebt Collection’)]")
#elu.click()

elv = driver.find_element_by_xpath(’//android.widget.TextView[@text= “Baddebt Collection”]’)
elv.click()

#elk = driver.find_element_by_name(“Baddebt Collection”)
#elk.click()

#el78 = driver.find_element_by_id(“com.ambs.mobile:id/txtValue_Spinner”)
#el78.click()

#elb = driver.find_element_by_xpath("//*[@name=‘Baddebt Collection’]")
#elb.click()

The clickable flag shows ‘False’ in the inspector. Can you check with your developers to see if they can set it to True and retry?

Even Im also facing same error <STA.DUT object at 0x7fd9827cb400>
ble_device_name=Dualstack1#ble_manf_name=1234#prov_ssid=DualStack2#prov_password=InnoQA2023$
Traceback (most recent call last):
File “/home/admin1/Desktop/temp_soma/test-automation-master-iot/./test_cases/DualStack/Wifi_provision.py”, line 184, in
driver.find_element(By.XPATH, “//android.widget.TextView[@content-desc=‘BLE Provisioning’]”).click()
File “/usr/local/lib/python3.10/dist-packages/appium/webdriver/webdriver.py”, line 381, in find_element
return self.execute(RemoteCommand.FIND_ELEMENT, {‘using’: by, ‘value’: value})[‘value’]
File “/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py”, line 344, in execute
self.error_handler.check_response(response)
File “/usr/local/lib/python3.10/dist-packages/appium/webdriver/errorhandler.py”, line 125, in check_response
raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace))
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
NoSuchElementError: An element could not be located on the page using the given search parameters.
at AndroidUiautomator2Driver.findElOrEls (/home/admin1/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/find.ts:87:11)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at AndroidUiautomator2Driver.findElOrElsWithProcessing (/home/admin1/.nvm/versions/node/v18.18.2/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:60:12)
at AndroidUiautomator2Driver.findElement (/home/admin1/.nvm/versions/node/v18.18.2/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:75:12)
The code here is: lass AppiumBLETest:

def perform_provision(self, element_text='DualStack2'):
    desired_cap = {
        "platformName": "Android",
        "platformVersion": "11",
        "deviceName": "RZ8M71M2E9X",
        "appPackage": "com.innophase.provisioning",
        "appActivity": ".MainActivity",
        "automationName": "UiAutomator2",
        "noReset": "true",
        "appium:connect_timeout": 30
    }
    options = UiAutomator2Options().load_capabilities(desired_cap)
    driver = webdriver.Remote("http://0.0.0.0:4723/wd/hub", options=options)
    time.sleep(5)
    print("Launching BLE Provisioning app")
    driver.find_element(By.XPATH, "//android.widget.TextView[@content-desc='BLE Provisioning']").click()
    time.sleep(10)
    print("Clicking on scan now!")
    driver.find_element(By.XPATH, "//android.widget.TextView[@text='Scan Devices']").click()
    #time.sleep(5)

    driver.find_element(By.XPATH, "//android.widget.TextView[contains@text='DualStack1')]").click()
    print("Selecting the device")
    driver.implicitly_wait(10)
    ssid = driver.find_element(By.XPATH, "//android.widget.TextView[contains(@text,'DualStack2')]").click()
    driver.implicitly_wait(10)
    driver.find_element(by=AppiumBy.XPATH, value="//android.widget.EditText[@text='Password']").send_keys(
        "InnoQA2023$")
    print("Provisioning done successfully")
    time.sleep(10)
    driver.find_element(by=AppiumBy.XPATH, value="//android.widget.TextView[@text='Submit']").click()

Could anyone please check and help on to resolve this? @Venkatesh_Akula @sumaiya27
I’m using Appium 2.0.1