简体   繁体   中英

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.

I have written a simple script to identify a web element (input text box) through a locater. The locator can be xpath,name or id.

THe script works fine when executed through the console but fails when executed through Jenkins.If I remove these locators my scripts works fine in Jenkins (installed on the local machine). I tried to install selenium plugin in Jenkins but still same error. In Jenkins I am getting this error

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

Below is my script that fails

** 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

(I am adding sleep to ensure its not the timing issue.)

The below script works fine in 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

Initially I was getting the same error in console but then I installed selenium version 3.3.0 in PhyCharm IDE and it resolved the problem at the console-level

Any thoughts would be much appreciated.

It's failing because it's using a newer version of selenium , which removed some deprecated methods, such as find_elements_by_name and find_elements_by_xpath in version 4.3.0 . See the CHANGES: 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

You now need to use the following methods for your situation:

driver.find_elements("name", NAME)

or

driver.find_elements("xpath", XPATH_SELECTOR)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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