当尝试从自定义库访问关键字时,显示错误 InvalidArgumentException
我使用下面的文件夹结构来维护我的测试脚本
Test_Scripts
TestCase
TestSuite1.robot
SupportFiles
RF_CustomLibrary.py
Run Code Online (Sandbox Code Playgroud)
TestSuite1.机器人
*** Settings ***
Library SeleniumLibrary
Library ..\\SupportFiles\\RF_CustomLibrary.py
*** Variables ***
${Browser} Chrome
*** Test cases ***
Sample Test Case
Verify Paste text functionality
*** Keywords ***
Verify Paste text functionality
Set Library Search Order RF_CustomLibrary
Open Browser https://gmail.com ${BROWSER}
Sleep 2s
Maximize Browser Window
Wait Until Keyword Succeeds 60s 2s Element Should Be Visible ${L_Login_btn}
PasteTextFunction id=identifierId Username1
Run Code Online (Sandbox Code Playgroud)
自定义库:RF_CustomLibrary.py
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from SeleniumLibrary import SeleniumLibrary
from SeleniumLibrary.base import LibraryComponent, keyword
from SeleniumLibrary.errors import ElementNotFound
from SeleniumLibrary.utils import is_noney
class RF_CustomLibrary(SeleniumLibrary):
@keyword
def pasteTextFunction(self, locator, text):
os.system("echo off | clip")
os.system("echo %s| clip" % text.strip())
element = self._current_browser().find_element(locator)
element.clear()
element.send_keys(Keys.CONTROL, 'v')
Run Code Online (Sandbox Code Playgroud)
当我执行此测试用例时,针对关键字“ PasteTextFunction ”显示以下错误消息
InvalidArgumentException: Message: invalid argument: invalid locator
Run Code Online (Sandbox Code Playgroud)
任何解决此错误的建议/输入都会有所帮助。
您正在调用低级 selenium 函数find_element,但传入了 SeleniumLibrary 样式的定位器 ( id=identifierId),这不是低级 selenium 驱动程序能够理解的东西。
如果要使用 SeleniumLibrary 定位器,则需要使用 SeleniumLibrary 的Get webelement方法。
element = self.get_webelement(locator)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
596 次 |
| 最近记录: |