Home > Blockchain >  Pytest Selenium - Selecting Elements As List
Pytest Selenium - Selecting Elements As List

Time:01-30

I have a webpage containing inventory_container that has multiple elements under it (products).

I want to ask if there is a way to select all child elements under 1 specific as a list and select them as I please for example, by text or class.

example for elements

CodePudding user response:

Try this:

inventory_items = driver.find_elements(By.CLASS_NAME, 'inventory_item')
print(len(inventory_items)
for each_item in inventory_items:
    your code here

CodePudding user response:

Yes you can do this buy reached the parent first then looking for direct childs only for this you can use css-selector.

inventory_items = driver.find_elements(By.CSS_SELECTOR, 'div[] > div')

Now you have a list of web elements you can iterate each child element in loop.

  •  Tags:  
  • Related