JMeter jp@gc-WebDriver 采样器元素名称是动态的

时间:2021-02-03 12:55:51

标签: selenium-webdriver jmeter

我尝试在 Chrome 的 JMeter WebDriver 中编写一些代码。我发现 ID 名称是动态的。重新加载 Chrome 浏览器时,名称将更改

例如: 第一次加载:

WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[@id='dropdown-menu-2724']/li")).click();

第二次加载:

WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[@id='dropdown-menu-3607']/li")).click();

这会导致 Element not found 消息的错误。

1 个答案:

答案 0 :(得分:0)

如果没有其他方式通过其他方式(文本、父级、子级等)唯一标识元素,您可以使用 XPath contains() function 对选择器进行部分匹配。

类似于:

//ul[contains(@id,'dropdown-menu-')]/li

您可能还会发现 The WebDriver Sampler: Your Top 10 Questions Answered 篇文章很有用。

相关问题