2

I am trying to write custom function using robot framework existing Seleniumlibrary in python to get link from element. But I am keep getting an issue in get_attribute.

Error : 'list' object has no attribute 'get_attribute'

Library imported

from selenium import webdriver
from robot.libraries.BuiltIn import BuiltIn

def get_one_links(locator,attribute):
    lib = BuiltIn().get_library_instance('SeleniumLibrary')
    links = lib.find_elements(locator).get_attribute(attribute)
    return links
0

1 Answer 1

3

That's because you are trying to call the method on a list, you can only call on a single element. See the example below. The "get_attribute" property doesn't exist for lists, but the "get_attribute" property does for single element. For example:

You need to do something like this in your code,

from selenium import webdriver
from robot.libraries.BuiltIn import BuiltIn

def get_one_links(locator,attribute):
    lib = BuiltIn().get_library_instance('SeleniumLibrary')
    links = lib.find_elements(locator)
    for link in links:
        return link.get_attribute('href')
        #return link if thats what you want
Sign up to request clarification or add additional context in comments.

9 Comments

When driver is driver = webdriver.Chrome("C:\Path\To\chromedriver.exe")
But you are not calling existing robot framework Selenium library. I want to use existing library.
I haven't changed anything related to robot framework. The method getAttribute() is a method that is declared in WebElement interface, and native to selenium. You just need to apply the operation differently to get your results
items = driver.find_elements_by_tag_name("a") does not work in robot framework existing library. driver is only available when webdriver.chrome declare. But in my case I am calling existing library. existing Library does not recognize driver.
I have updated my code. The earlier example was supposed to be an unrelated example on how it would work. Can you see the update now.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.