serhatbolsu / robotframework-appiumlibrary

AppiumLibrary is an appium testing library for RobotFramework
Apache License 2.0
403 stars 291 forks source link

Appium/Android Unable to click on the WebElement #168

Closed arthurmx closed 2 years ago

arthurmx commented 7 years ago

I'm trying to use WebElement list to be able to select elements by index. I am using Appium keyword - Get Web Element following an example from documentation: @{elements} Get Webelements class=UIAButton Click Element @{elements}[2]

The issue is that I am getting the following error: UnboundLocalError: local variable 'elements' referenced before assignment This is working fine in Desktop Tests using the Selenium2Library

Can someone advise, please?

Environment

Appium-Python-Client (0.24)

Appium v1.6.3 robotframework (3.0.2) robotframework-androidlibrary (0.2.0) robotframework-appiumlibrary (1.4.3) robotframework-selenium2library (1.7.4) robotframework-uiautomatorlibrary (0.4) selenium (3.3.1) uiautomator (0.3.2)

Details

KEYWORD @{TEST} = AppiumLibrary . Get Webelements xpath=//android.widget.Button

Documentation: Returns list of WebElement objects matching locator. Start / End / Elapsed: 20170404 16:00:57.309 / 20170404 16:00:57.527 / 00:00:00.218 16:00:57.310 DEBUG POST http://127.0.0.1:4723/wd/hub/session/c7931dfd-0029-4ed4-8508-ec333cf5d3fd/elements {"using": "xpath", "sessionId": "c7931dfd-0029-4ed4-8508-ec333cf5d3fd", "value": "//android.widget.Button"}

16:00:57.526 DEBUG Finished Request

16:00:57.527 INFO @{TEST} = [ <appium.webdriver.remote.webelement.WebElement (session="c7931dfd-0029-4ed4-8508-ec333cf5d3fd", element="1")> | <appium.webdriver.remote.webelement.WebElement (session="c7931dfd-0029-4ed4-8508-ec333...

Start / End / Elapsed: 20170404 16:00:57.528 / 20170404 16:00:57.531 / 00:00:00.003 00:00:00.004 KEYWORD AppiumLibrary . Click Element ${TEST[0]}

Documentation: Click element identified by locator. Start / End / Elapsed: 20170404 16:00:57.532 / 20170404 16:00:57.536 / 00:00:00.004 00:00:00.000 KEYWORD Capture Page Screenshot

Start / End / Elapsed: 20170404 16:00:57.533 / 20170404 16:00:57.533 / 00:00:00.000 16:00:57.533 FAIL Multiple keywords with name 'Capture Page Screenshot' found. Give the full name of the keyword you want to use: AppiumLibrary.Capture Page Screenshot Selenium2Library.Capture Page Screenshot

16:00:57.532 INFO Clicking element '<appium.webdriver.remote.webelement.WebElement (session="c7931dfd-0029-4ed4-8508-ec333cf5d3fd", element="1")>'.

16:00:57.536 FAIL UnboundLocalError: local variable 'elements' referenced before assignment

16:00:57.536 DEBUG Traceback (most recent call last): File "", line 2, in click_element File "C:\Python27\lib\site-packages\AppiumLibrary\keywords\keywordgroup.py", line 15, in _run_on_failure_decorator return method(*args, **kwargs) File "C:\Python27\lib\site-packages\AppiumLibrary\keywords_element.py", line 42, in click_element self._element_find(locator, True, True).click() File "C:\Python27\lib\site-packages\AppiumLibrary\keywords_element.py", line 573, in _element_find return elements

Code To Reproduce Issue The bellow example can quickly reproduce the issue using the Android Calculator App

AppiumLibrary.Open Application http://localhost:4723/wd/hub platformName=Android deviceName='emulator-5554' appPackage=com.android.calculator2 appActivity=com.android.calculator2.Calculator @{TEST} AppiumLibrary.Get Webelements xpath=//android.widget.Button log to console ${TEST} AppiumLibrary.Click Element ${TEST[1]}

serhatbolsu commented 7 years ago

I feel like this is most probably a syntax issue. I dont see the exact formation of your suite however please try to use "@" array sign as it is in example from


@{elements}  get webelements  //locator
click element  @{elements}[${index}]
arthurmx commented 7 years ago

thanks for your reply, I tried that before and received the same error @{elements} AppiumLibrary.Get Webelements xpath=//android.widget.Button AppiumLibrary.Click Element @{elements}[1]

As I mentioned above, the following approach works fine with Selenium2Library: ${Elements} get webelements xpath=//*[@id='devices']/div/div click element ${Elements[10]} I am not getting error and and the element is clicked

Start / End / Elapsed: 20170404 23:11:57.881 / 20170404 23:11:57.881 / 00:00:00.000 23:11:57.881 FAIL

23:11:57.880 INFO Clicking element '<appium.webdriver.remote.webelement.WebElement (session="c5812cda-96e0-4cfd-9f65-a906a15ef9d2", element="2")>'.

23:11:57.885 FAIL UnboundLocalError: local variable 'elements' referenced before assignment

serhatbolsu commented 2 years ago

Closing due to inactivity