0

I am writing a script in Python using selenium that automates a store checkout. It launches to the site, finds the first item that matches the criteria, hits checkout, then proceeds top purchase. I am trying to find out how to make it select a specific color. The shop I am buying from updates the store every week with new items, so I won't have the XPATH available to me.

There is a button to change the color, and I need help being able to select the button.

The store has multiple buttons with the product in different colors as a way to choose between them.

The button to change colors has ONE specific attribute titled "data-style-name"="(color)" enter image description here

I will not have any other attribute, link, or ID known to me, thus searching for this attribute seems like the only way to find it. The picture above is a snippet from pre-existing items on the storepage as an example.

(Note that above it says class="selected" because the "black" jacket has been clicked on while taking this screenshot. Example of a jacket that has not been clicked on:

enter image description here

Anyone have any ideas on the way to go about this?

Daniel Larson
  • 49
  • 1
  • 9

1 Answers1

1

Inspired by this and this, and a bit of reading up on CSS selectors but something like:

elem = driver.find_element_by_css_selector('button[data-style-name]')

Might work for you

user15270287
  • 1,123
  • 4
  • 11