繁体   English   中英

我的机器人流程自动化脚本在通过本地 Jenkins 执行时失败,但在通过控制台运行时工作正常

[英]My robot process automation script fails when executed through local Jenkins but works fine when run through console

Framework=Robot Process Automation
IDE=Pycharm
Libary= mutliple libabaries selenium, robotframework etc.

我编写了一个简单的脚本来通过定位器识别 web 元素(输入文本框)。 定位器可以是 xpath、名称或 ID。

该脚本在通过控制台执行时工作正常,但在通过 Jenkins 执行时失败。如果我删除这些定位器,我的脚本在 Jenkins(安装在本地计算机上)中工作正常。 我尝试在 Jenkins 中安装 selenium 插件,但仍然出现同样的错误。 在 Jenkins 我收到这个错误

AttributeError: 'WebDriver' object has no attribute 'find_elements_by_name'
AttributeError: 'WebDriver' object has no attribute 'find_elements_by_xpath'

以下是我失败的脚本

** Settings ***
Library  SeleniumLibrary

*** Variables ***
${url}  https://login

${browser}      Chrome

*** Test Cases ***
open browser      ${url}    ${browser}
    sleep  10
   input text   name:username     Admin
    sleep  10
   input text   xpath://body/div[@id='app']/div[1]/div[1]/div[1]/div[1]/div[2]/div[2]/form[1]/div[2]/div[1]/div[2]/input[1]        admin123
    sleep  10

(我正在添加睡眠以确保它不是时间问题。)

以下脚本在 Jenkins 中运行良好

*** Settings ***
Library  SeleniumLibrary

*** Variables ***
${url}  https://
${browser}      Chrome
*** Test Cases ***
PageTitle
    open browser      ${url}    ${browser}
    sleep  2
    title should be   Robot Framework
    close browser

最初我在控制台中遇到了同样的错误,但后来我在 PhyCharm IDE 中安装了 selenium 版本 3.3.0,它在控制台级别解决了问题

任何想法将不胜感激。

它失败了,因为它使用的是更新版本的selenium ,它删除了一些已弃用的方法,例如版本4.3.0中的find_elements_by_namefind_elements_by_xpath 查看更改:https://github.com/SeleniumHQ/selenium/blob/a4995e2c096239b42c373f26498a6c9bb4f2b3e7/py/CHANGES

Selenium 4.3.0
* Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
* Deprecated Opera support has been removed (#10630)
* Fully upgraded from python 2x to 3.7 syntax and features (#10647)
* Added a devtools version fallback mechanism to look for an older version when mismatch occurs (#10749)
* Better support for co-operative multi inheritance by utilising super() throughout
* Improved type hints throughout

您现在需要根据您的情况使用以下方法:

driver.find_elements("name", NAME)

或者

driver.find_elements("xpath", XPATH_SELECTOR)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM