如何获取xpath

How to get the xpath

如何在给定页面上获取连衣裙类别的 xpath(带有连衣裙文本的图像)

https://www.amazon.com/b/ref=af_spr22_L1_w_nav_1?pf_rd_r=5FE3DS056G2PHQZPGCQV&pf_rd_p=e8199fbf-0485-4dda-aa8b-cc7a20b4c115&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=merchandised-search-6&pf_rd_t=30901&pf_rd_i=7147440011&node=1040660

我试过这个: Actions action = new Actions(driver);

WebElement 服装风格 = driver.findElement(By.xpath("//span[@data-csa-c-id='8nt4i-t93vdn-vkyjb-b2c2aj']")); action.moveToElement(服装风格).build().perform();

但是 NoSuchElementException 来了

尝试寻找更简单的 Xpath,你的似乎是基于 auto-generated 数据,所以很快就会过期。 尝试类似的东西:

//img[@alt='Dresses']/../../parent::a

//img[@alt='Dresses']/parent::div

此外,如果您只需要打开部分,单击元素就足够了:

WebElement clothestyle = driver.findElement(By.xpath("//img[@alt='Dresses']/../../parent::a"));
clothestyle.click();