【问题标题】:Cannot input text or Press Keys or Press Keycode无法输入文本或按键或按键码
【发布时间】:2021-03-28 04:59:02
【问题描述】:

我对机器人框架非常陌生,在 pycharm 工作。 我只想在当前字段中输入一些文本。但这些都不起作用。 我试过了

Press Keycode  a
Press Keys     text_field       q
input text      ${mylocator}     ${string-abc}


If I am using the correct library?

        *** Settings ***
        Library  AppiumLibrary  run_on_failure=AppiumLibrary.CapturePageScreenshot
        Library      Selenium2Library   run_on_failure=AppiumLibrary.CapturePageScreenshot
    
       *** Variables ***
       ${MsgEditor}     //*[@class='android.widget.RelativeLayout' and @resource-id='com.test.abc.work.cac:id/editor']
    
    *** Test Cases ***
    Add item
         Press Keys    text_field     q <--error browser not open
        \\or
        appiumlibrary.Input Text    ${MsgEditor}    update <== error Message: Cannot set the element to 'update'. Did you interact with the correct element?

更新了 Press Keys 仍然失败。错误:

KEYWORD Selenium2Library . Press Keys text_field, q
Documentation:  
Simulates the user pressing key(s) to an element or on the active browser.

Start / End / Elapsed:  20201218 10:05:20.575 / 20201218 10:05:21.339 / 00:00:00.764
00:00:00.755KEYWORD AppiumLibrary . Capture Page Screenshot
10:05:20.575    TRACE   Arguments: [ 'text_field' | 'q' ]   
10:05:20.581    INFO    Sending key(s) ('q',) to text_field element.    
10:05:21.339    FAIL    No browser is open. 
10:05:21.339    DEBUG   Traceback (most recent call last):
  File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\__init__.py", line 471, in run_keyword
    return DynamicCore.run_keyword(self, name, args, kwargs)
  File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\robotlibcore.py", line 103, in run_keyword
    return self.keywords[name](*args, **(kwargs or {}))
  File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\keywords\element.py", line 895, in press_keys
    element = self.find_element(locator)
  File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\base\context.py", line 74, in find_element
    return self.element_finder.find(locator, tag, True, required, parent)
  File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\locators\elementfinder.py", line 74, in find
    parent=parent or self.driver)
  File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\base\context.py", line 32, in driver
    return self.ctx.driver
  File "c:\users\tester\pycharmprojects\androidtest\venv\lib\site-packages\SeleniumLibrary\__init__.py", line 547, in driver
    raise NoOpenBrowser('No browser is open.')

输入文本失败。我在其他领域也有同样的 InputText 并且可以工作。我尝试使用该定位器点击不同的字段并且它有效。 该应用程序在该元素上有问题吗?但我可以在点击字段后手动按下键盘。

【问题讨论】:

    标签: robotframework appium-android


    【解决方案1】:

    我建议先阅读官方文档:http://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html 和用户指南:https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html

    Press Keys 不是 AppiumLibrary 中的关键字。这是来自 SeleniumLibrary (https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Press%20Keys) 的关键字,但您没有将其导入到您的项目中。而且即使你导入了它,这个关键字也有两个参数(定位器和键),所以你需要正确使用它。

    *** Test Cases ***
         Press Keys     a
    

    除了我说的,没有测试用例名称,这是不正确的,不起作用,它实际上会给你以下错误:

    测试用例名称不能为空。

    您正确使用了 AppiumLibrary 中的 Input Test 关键字。但是,您可能需要验证您的定位器是否正确。我们不能这么说,因为您没有在问题中包含该信息。

    【讨论】:

    • 很抱歉,我只是剪切了部分测试用例。测试用例名称在那里。没问题。
    • 定位器也是正确的,因为我可以点击它。只是那个按键不起作用。我没有看到任何插入的密钥。
    • 好的,我在按键时看到了错误,我需要 text_field 然后是 value。
    • 我刚刚尝试了按键,但浏览器上的错误未打开。
    【解决方案2】:

    我使用了另一种方法。 adb shell 输入文本以触发文本

    【讨论】:

    • 你能提供一个你使用的shell命令的具体例子吗?
    猜你喜欢
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 2015-02-17
    • 1970-01-01
    相关资源
    最近更新 更多