问题
Hello I'm pretty new to Selenium and I'm trying to figuere out how to click a button which changes the selected shoe size on footlocker.com. Here is the product page I'm using for testing.
I click on the USA tab for sizing and then I would like to click on a size but i cant figure out how to find the specific li element.
<li class="fl-product-size--item" data-form-field-target="SKU" data-form-field-base-css-name="fl-product-size--item" data-form-field-value="314521665704105" data-form-field-unselect-group="" data-testid="fl-size-314521665704-44_5" data-product-size-select-item="314521665704105">
44,5</li>
Sorry if I did anything wrong while posting. I'm new here.
回答1:
Use the Firebug extension in Firefox to find your element. Then copy the XPath from there and use driver.FindElement(By.XPath("xpath goes here"));
To find all elements on the page by the list tag, you can use driver.FindElements(By.TagName("li"))
To find the specific element by its class name, you can use driver.FindElement(By.ClassName("fl-product-size--item"))
回答2:
To find that specific li element using its specific class selector, your best option is to use a css selector:
driver.FindElement(By.CssSelector("li.fl-product-size--item""));
Hope this helps
来源:https://stackoverflow.com/questions/38723729/finding-shoe-size-element-with-selenium