I am writing automated tests for an angular/clarity application and I want to first
type
some text into an input field and afterwards select an option from a datalist.
Setting the text to the input field works fine but when attempting to click on the
option element I get the following exception:
Caused by: org.openqa.selenium.JavascriptException: javascript error: option element is not in a select
I have already tried clicking it with selenium and javascript. Below is the code for both.
@Override
public void click(String xpath, MouseButton button, ClickPosition position)
{
LOG.info("Clicking on element '{}' with Mouse Button '{}' on Position '{}'!", xpath, button, position);
final WebElement element = find(xpath);
//in case we have a standard click (left on center) we spare out the whole calculation and just use standard click
if (button == MouseButton.LEFT && position == ClickPosition.CENTER)
{
element.click();
}
else
{
final Dimension size = element.getSize();
// opposite to the javadoc, the Actions#moveToElement() method is relative to the center and not to the top left corner with selenium api version 3.14.0
// REMARK: there is an issue currently filed so may be changed back at some point
final Point relativePoint = position.calculateRelativePointFromCenter(size.width - 1, size.height - 1);
performActions(a -> {
try
{
a.moveToElement(element, relativePoint.x, relativePoint.y);
switch (button)
{
case LEFT:
a.click();
break;
case RIGHT:
a.contextClick();
break;
case MIDDLE:
default:
throw new UnsupportedOperationException("Unexpected click button: " + button);
}
}
catch (final WebDriverException e)
{
if (e.getMessage().contains("Element is not clickable"))
{
throw new ElementNotClickableException("Unable to click on element with XPath '" + xpath + "'",
e);
}
}
});
}
}
@Override
public void javascriptClick(String xpath)
{
LOG.info("Triggering click event on element '{}' via javascript!", xpath);
parent.executeJavascript("arguments[0].click();", find(xpath));
}
System info: host: 'XXX', ip: 'XXX', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {browserName: chrome, browserVersion: 84.0.4147.125, chrome: {chromedriverVersion: 84.0.4147.30}
Does anyone have a clue about whats wrong here?
