如何构建定位器来识别此元素?



这个HTML的XPath/CSS应该是什么?要执行 MovetoElement,我需要检查此元素,我尝试使用//a[@class='product-name']但选择了多个节点。

<a class="product-name" itemprop="url" title="Faded Short Sleeve T-shirts" href="http://automationpractice.com/index.php?id_product=1&controller=product"> Faded Short Sleeve T-shirts </a>

该网站有两个主要部分,流行和畅销书。每个定位器都具有与您正在使用的定位器相匹配的元素。POPULAR位于ID为homefeaturedUL下。畅销书位于 ID 为blockbestsellersUL下。

另一个问题是,您的定位器同时找到围绕产品图像的A标签和另一个用于产品名称的标签。您可以使用其中任何一个,因为两者的href相同,但如果需要,您可以指定每个。产品图片链接标有类product_img_link。产品名称标有类product-name

把这一切放在一起...

流行>产品名称

#homefeatured a.product-name[title='Faded Short Sleeve T-shirts']

热门>产品图片

#homefeatured a.product_img_link[title='Faded Short Sleeve T-shirts']

畅销书>产品名称

#blockbestsellers a.product-name[title='Faded Short Sleeve T-shirts']

畅销书>产品图片

#blockbestsellers a.product_img_link[title='Faded Short Sleeve T-shirts']

注意:仅当选择该选项卡时,"流行"页面上的元素才可见。"畅销书"选项卡上的元素仍然存在,但不可见,如果您尝试与它们交互,则会抛出。

试试这个:

//a[@title='Faded Short Sleeve T-shirts']

最新更新