Query:
In Python using Selenium, one aims to retrieve the .val() of a
<code class="python">def test_chart_renders_from_url(self): url = 'http://localhost:8000/analyse/' self.browser.get(url) org = driver.find_element_by_id('org') # Retrieve org value?</code>
How can this be achieved? Selenium documentation provides ample information on element selection, but not on how to access attributes.
Response:
To access the desired attribute, utilize the get_attribute() method. An example is provided below:
<code class="python">def test_chart_renders_from_url(self): url = 'http://localhost:8000/analyse/' self.browser.get(url) org = driver.find_element_by_id('org') # Retrieve org value? val = org.get_attribute("attribute name")</code>
The above is the detailed content of How to Retrieve an HTML Element\'s Attribute Using Selenium in Python?. For more information, please follow other related articles on the PHP Chinese website!