如何使用 Selenium WebDriver 与 Angular ColorPicker 组件交互?

How to interact with Angular ColorPicker components using Selenium WebDriver?

如何使用 Selenium WebDriver 与 Angular ColorPicker 组件交互?没有十六进制代码的文本字段输入,它完全通过鼠标点击操作。可以在这里看到它的一个例子:https://www.primefaces.org/primeng/showcase/#/colorpicker

有趣的问题。

你有句柄对象:

div[class*='p-colorpicker-hue-handle']

您可以尝试通过 Selenium 向上或向下拖动它

要选择颜色,您可以找到“主”颜色选择器并点击它的中心,而不是点击它的偏移量:

cssExpression: "div[class='ng-trigger-overlayAnimation'][class='p-colorpicker-panel']"

WebElement element = browser.findElement(By.
cssSelector(cssExpression));
Actions builder = new Actions(browser);
Action action = builder.moveToElement
(element, -20, -20).click().build();
action.perform();

您可以使用这些值并在 X -50 中移动,例如在 Y -70 中移动。