Finding shoe size element with selenium

社会主义新天地 提交于 2019-12-25 04:16:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!