java - 无法在 http://automationpractice.com 上找到元素
问题描述
我使用下面的 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 不起作用。
解决方案
因为属性值: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()
来删除新行和多余的空格。</p>
//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!']
推荐阅读
- angular - 角度的后端分页是否总是刷新屏幕
- r - 从日期向量中选择和分组相似的日期
- asynchronous - 在 python 中服务 web 请求,产生一个新的长时间运行的子进程
- python - 查找列中的值与列表 Python 中的值不匹配的行
- php - Laravel-Lighthouse 范围未更新
- html - 如何使用引导程序和 jQuery 创建过滤器
- google-apps-script - 使用脚本编辑器在设置时间间隔上更新 Vlookup 公式
- javascript - 在 Google Earth Engine 的 Java 编辑器中创建重复第一个元素并添加 _1 _2 到 _n 的字符串列表
- appium - 我用Appium连接手机app,但是出现权限错误
- c# - 如何根据行单元格值在 GuiGridView 中选择一行?