我使用下面的xpath在http://automationpractice.com上定位了一个元素
driver.findElement(By.xpath("//a[@title = 'Choose from t-shirts, tops, blouses, short sleeves, long sleeves, tank tops, 3/4 sleeves and more. Find the cut that suits you the best!']")).click();
我不确定是什么问题。
如果我尝试使用Linktext来找到它,那还是可以的,但是我想知道为什么上面的xpath无法起作用。
答案 0 :(得分:0)
因为attribute:title的值包括换行,但是您在一行中给出了所有字符串。
只需将值复制到记事本中,即可获得以下字符串:
You will find here all woman fashion collections.
This category includes all the basics of your wardrobe and much more:
shoes, accessories, printed t-shirts, feminine dresses, women's jeans!
您可以使用字符串函数normalize-space()
删除新行和多余的空间。
//a[normalize-space(@title)='Choose from t-shirts, tops, blouses, short sleeves, long sleeves, tank tops, 3/4 sleeves and more. Find the cut that suits you the best!']