Suppose there are multiple buttons in a web page
<button id='xyz'></button>
<button id='abc'></button>
<button id='pqr'></button>
I want the value of the id attributes of all the buttons using selenium
I am using this code
for button in driver.find_elements(by=By.XPATH,value='//button'):
print(button.get_attribute('id'))
I am not getting any thing in the output
Considering the HTML
To extract the value of the
id
attributes of the<button>
elements you have to induce WebDriverWait for visibility_of_all_elements_located() and using List Comprehension you can use either of the following locator strategies:Using TAG_NAME:
Using CSS_SELECTOR:
Using XPATH:
Note : You have to add the following imports :