Reputation: 65
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
Upvotes: 2
Views: 1030
Reputation: 7744
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
Upvotes: 3