我使用下面的文件夹结构来维护我的测试脚本
Test_Scripts
TestCase
TestSuite1.robot
SupportFiles
RF_CustomLibrary.py
测试套件1.robot
*** 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
自定义库: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')
当我执行此测试用例时,将为关键字“显示以下错误消息”
PasteTextFunction函数
"
InvalidArgumentException: Message: invalid argument: invalid locator
任何解决此错误的建议/输入都会很有帮助。