Reputation: 569
http://store.nike.com/us/en_us/pw/mens-nikeid-shoes/7puZoolZoi3
I am trying to click the first shoe listed in the store. I need to know how to reliably click the first shoe, as the store inventory changes daily, so I'm worried that if I write this myself without checking, the script could break when the shoe inventory changes.
Should I be using xpath or css_selector?
How do I do correctly do:
driver.find_element_by_css_selector("firstshoe").click()
Upvotes: 1
Views: 5858
Reputation: 136
You can also use below XPath to find the first link in the grid
//*[contains(@class,'grid-item')]/a)[1]
Upvotes: 1
Reputation: 474091
The following CSS selector would match all products (shoes) on the page:
.grid-item.nikeid
And if you use driver.find_element_by_css_selector(".grid-item.nikeid").click()
- you would click the first shoe on the page.
Upvotes: 1