是否可以使用可访问性名称和角色使用C# selenium找到元素?
有关更多细节,请参见规范:https://www.w3.org/TR/accname-1.1
其基本原理是,我们有一个具有大量单元测试的react项目,这些单元测试已经使用了基于角色/名称的查询的目标元素--重用角色/名称是很好的,而不必更改标记来添加纯粹用于基于硒的验收测试的ids。是否存在与测试库中的getByRole查询等效的selenium?
所需的示例
构成部分:
<button>Cancel</button>单元测试:
const cancelButton = screen.getByRole("button", { name: "Cancel" })验收测试(如何完成?):
IWebElement cancelButton = driver.FindElement(By.???("button", "cancel"));试图避免
构成部分:
<button id="cancel-button">Cancel</button>单元测试:
const cancelButton = screen.getByRole("button", { name: "Cancel" })验收测试:
IWebElement cancelButton = driver.FindElement(By.Id("cancel-button"));发布于 2022-05-17 17:21:00
如果您想要一个button元素完全包含字符串'Cancel' (即您想要一个精确的匹配),那么运行以下命令
driver.FindElement(By.XPath('//button[text()="Cancel"]'))否则,如果字符串(如'foo Cancel bar' )也被接受,则运行以下命令
driver.FindElement(By.XPath('//button[contains(text(), "Cancel")]'))https://stackoverflow.com/questions/72274130
复制相似问题