Frage

I am using Selenium to automate a UI using Java language.

I have an action button and when the User hover overs the mouse on Action button, it gives two clickable options - Create and Edit

I have stored CSS locators as Enums for Action button and also for Create and Edit (clickable) links as ACTIONBUTTON, CREATEACTION, EDITACTION respectively.

I used a Java code like below but it gives an error saying java.lang.ClassCastException: org.openqa.selenium.By$ByCssSelector cannot be cast to org.openqa.selenium.WebElement

Actions actions = new Actions(driver);
actions.moveToElement((WebElement) DCSAdminEnums.ACTIONBUTTON.getLocator());

actions.moveToElement((WebElement) DCSAdminEnums.CREATEACTION.getLocator());
actions.click();
actions.perform();

Please suggest you can help a better way to handle this, using the Enums that I have.

UPDATE: I also tried with the below style of code but it did not work :-(

WebElement menu = driver.findElement((By.xpath("//*[@id='button-1177-btnInnerEl']")));
WebElement submenu = driver.findElement((By.cssSelector("a[id='menuitem-1175-itemEl']")));
Actions action = new Actions(driver);
action.moveToElement(menu).perform();
Thread.sleep(2000);
action.click(submenu).perform();
War es hilfreich?

Lösung

By and WebElement are different type, hence the compilation error.

If you are talking about actions are not performed, then that's a totally different thing from your original post. Please ask a new question.

WebbElement can be retrieved by driver.findElement(By locator), so you need to use driver.findElement(yourLocator) to get element first.

Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(DCSAdminEnums.ACTIONBUTTON.getLocator()));
actions.moveToElement(driver.findElement(DCSAdminEnums.CREATEACTION.getLocator()));
actions.click().perform();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top