java - 单击 xpath 中具有动态 url 更改的元素
问题描述
我写的下面的css选择器。
.custom-scrollbar .content-row:nth-of-type(1) [src='https://static-qa.xxxxxxxxx.com/csp/images/rotate_action_icon.svg']
问题是我需要点击那个编辑按钮,但问题是 url 相对于 env 的变化。示例-当前它指向 qa,因此 url 是 qa,如果它在 prod 中,那么它将由于发生未找到 web 元素错误而改变。
我正在尝试使用以下不起作用的代码-
List<WebElement> list = pilot.findElements(By.tagName("img"));
String aa = list.get(3).getAttribute("src");
list.get(2).click();
请建议一种更好的方法来使用这些带有动态 url 的按钮。
解决方案
尝试使用以下 css 选择器startswith
和 endswith
img[src^='https://static-'][src$='com/csp/images/rotate_action_icon.svg']
推荐阅读
- php - Htaccess RewriteRule 给出内部服务器错误
- powerapps - 是否可以在 powerapps 的下拉列表中自定义文本?
- mysql - 将 Azure SQL 表中的数据链接并导出到我的 SQL 表
- elasticsearch - Elasticsearch:通过数组属性搜索多个文档
- c# - .NET Core 无法连接到 SQL DB
- system-verilog - 如何在垃圾收集时执行 SystemVerilog 代码?
- python - 如何使用 selenium 抓取网页 - find_element_by_link_text
- layout - Flutter:如何使Container的宽度等于Stackview的宽度?
- amazon-web-services - 我应该把 aws cloudfront 放在 ELB 前面吗?
- swift - 如何使用 applicationdidBecomeActive 函数呈现 ViewController,但有一些例外?