So I have the code where the user inputs a color variable and the string for it is called color. Example link - https://www.supremenewyork.com/shop/jackets/k56l3oteu/hjylineo1 . So next I try to find it on the website using
driver.find_element_by_xpath("//a[@data-style-name='{}'".format(color.get()))
The syntax is wrong and I am not sure how to find it correctly using the variable that users entered before. Also the question, when one of those colors was located how to choose that color as the checkout option, not sure if I explained it right. Thanks for any information
Try using the following CSS selector to identify the element:
It looks like that will uniquely identify the element that shows what color is chosen.
Then your color is stored in the inner HTML of the element, so you can grab that with something like
OK, I understand now that you want to use xPath to dynamically select an element based on the color. I noticed that the xPath
find the top-right element,
finds the middle-right element and so on...
Thus if you can simply use a map to map colors to the numbers, something like
(not sure if the colors match up correctly in my example but hope you get the idea)
Then,
should select the element with the color you specified.
Is that helpful? Let me know if you have any questions.
You can use string formats below, but there is error in your xpath - missing
]
at the end: