10 examples of 'how to get attribute value in selenium' in Python

Every line of 'how to get attribute value in selenium' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
192def get_element_attribute(self, element, attr, css=False, expected_value=None):
193 """
194 Get the value of an attribute or css attribute from an element.
195
196 :param element: CSS Selector or XPATH used to locate the element
197 :type element: str
198 :param attr: The attribute to lookup
199 :type attr: str
200 :param css: Whether or not this is a CSS atrribute
201 :type css: bool
202 :param expected_value:
203 :return: The value of the attribute
204 """
205 elem = self.get_element(element)
206 if css:
207 value = elem.value_of_css_property(attr)
208 if self.is_color(value):
209 value = Color.from_string(value)
210 if expected_value:
211 if self.is_color(expected_value):
212 expected_value = Color.from_string(expected_value)
213 return value, expected_value
214 else:
215 value = elem.get_attribute(attr)
216 return value
37def __getattribute__(self, name):
38 """
39 Pass ``__getattribute__`` directly to the first array element.
40 """
41 try:
42 attr = object.__getattribute__(self, 'elements')[0].__getattribute__(name)
43 except IndexError:
44 raise NoElementException(u'No elements found for selector: {0}'\
45 .format(object.__getattribute__(self, 'selector')))
46 return attr
201def attribute(self, name, ttl=None):
202 """Get the attribute with the given name
203
204 If there are multiple items in this object, the attribute of the first
205 element will be returned.
206
207 :param name: The name of the attribute
208 :param ttl: The minimum number of seconds to keep retrying
209 :returns: The attribute of the first element
210 """
211 def callback(elements):
212 return \
213 elements.item.get_attribute(name) if elements.items else None
214 return self.retried(callback, update=True, ttl=ttl)
83def _get_value(self):
84 if self._element.get_value():
85 return self._element.get_value()
86 else:
87 return self._element.get_text()
103def verifyAttribute(self, element, value):
104 """ Verify the value of an element attribute.
105 The syntax for returning an element attribute
106 is @attribute-name. """
107 return self.dispatchCommand("verifyAttribute", element, value)
63def attribute(name: str, value: str = None):
64 if value:
65 warnings.warn(
66 'passing second argument is deprecated; use have.attribute(foo).value(bar) instead',
67 DeprecationWarning)
68 return match.element_has_attribute(name).value(value)
69
70 return match.element_has_attribute(name)
42def test_accessing_attributes_of_inputs(self):
43 "should allow input's attributes retrieval"
44 button = self.browser.find_by_css('input[name="send"]').first
45 assert_equals(button['name'], 'send')
120def find_element_by_link_text(self, *args, **kwargs):
121 return self.__getattr_from_webdriver_or_webelement__('find_element_by_link_text')(*args, **kwargs)
98def fetch_element_att(html, css, attr):
99 """
100 Fetch the given elements specifed by the css selector from html
101 (an `Element` from lxml) and return the attribute (attr) of each.
102 """
103 rv = None
104 elements = html.cssselect(css)
105 if len(elements) == 1:
106 rv = elements[0].get(attr)
107 elif len(elements) > 1:
108 rv = ';'.join([e.get(attr) for e in elements])
109 return rv
1641def get_expression(self,expression):
1642 """
1643 Returns the specified expression.
1644
1645
1646 This is useful because of JavaScript preprocessing.
1647 It is used to generate commands like assertExpression and waitForExpression.
1648
1649
1650 'expression' is the value to return
1651 """
1652 return self.get_string("getExpression", [expression,])

Related snippets