Reputation: 1659
I am trying to loop through table elements on a page of our ERP system.
Based on a question I asked before I thought this would be a slam dunk - but I cannot figure it out.
Here's the latest code I've tried:
approved_suppliers = driver.find_elements_by_xpath("//tbody[@id='ApprovedSupplierBody']")
for supplier in approved_suppliers:
print('Supplier',supplier.id)
if I substitute print('Supplier',supplier.id)
with print('Supplier',supplier.value)
I get the following error:
AttributeError: 'WebElement' object has no attribute 'value'
In the screenshot example I want the code to print 300 Below
, and when there are multiple suppliers the names of the fields increase by 1.
For example, pik_Supplier_1
, pik_Supplier_2
, etc.
Upvotes: 3
Views: 780
Reputation: 50949
The element with id
ApprovedSupplierBody
is a single element, to get the elements with id
pikSupplier
you need to include it in the xpath
approved_suppliers = driver.find_elements_by_xpath("//tbody[@id='ApprovedSupplierBody']//input[starts-with(@id, 'pikSupplier')]")
To get the value you need to use get_attribute
to get the value property
supplier.get_attribute('value')
You need to do the same with id
, supplier.id
will return internal WebElement
's id
property, something like 92505ac9-2c32-447e-b94a-8c7398b53e0e
and not ApprovedSupplier
.
Upvotes: 4