用硒查找鞋码元素

Finding shoe size element with selenium

你好,我是 Selenium 的新手,我正在尝试弄清楚如何单击一个按钮来更改 footlocker.com 上的所选鞋码。这里是 the product page I'm using for testing.

我点击“美国”标签选择尺码,然后我想点击一个尺码,但我不知道如何找到特定的 li 元素。

<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>

抱歉,如果我在发帖时有任何错误。我是新来的。

在 Firefox 中使用 Firebug 扩展来查找您的元素。然后从那里复制 XPath 并使用 driver.FindElement(By.XPath("xpath goes here"));

要通过列表标签查找页面上的所有元素,可以使用driver.FindElements(By.TagName("li"))

要通过 class 名称查找特定元素,您可以使用 driver.FindElement(By.ClassName("fl-product-size--item"))

要使用特定的 class 选择器查找特定的 li 元素,最好的选择是使用 css 选择器:

driver.FindElement(By.CssSelector("li.fl-product-size--item""));

希望对您有所帮助