Utilizing Selenium with Java, you can hover over a button and choose to click on any of the available options

Currently, I am utilizing Selenium to automate the user interface using Java.

Within the UI, there is an action button that, when hovered over by the User, displays two clickable options - Create and Edit.

For ease of use, I have stored CSS locators as Enums for the Action button, as well as for the Create and Edit clickable links under the names ACTIONBUTTON, CREATEACTION, and EDITACTION respectively.

Initially, I attempted to implement the functionality with the following Java code snippet, but encountered an error stating 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();

I am seeking advice on a more optimal way to handle this scenario using the existing Enums.

UPDATE: I also tested an alternative approach with the code below, however, it unfortunately did not yield the desired outcome:

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();

Answer №1

WebElement and By are distinct types, hence the compilation error.

If you're referring to actions not being executed, that is a separate issue from your initial query. Please submit a new question for assistance.

To retrieve a WebElement, utilize driver.findElement(By locator). Therefore, you should use driver.findElement(yourLocator) to obtain the element first.

Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(DCSAdminEnums.ACTIONBUTTON.getLocator()));
actions.moveToElement(driver.findElement(DCSAdminEnums.CREATEACTION.getLocator()));
actions.click().perform();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with CSS3 animations

.button { background-color: #4CAF50; /* Green */ border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; ...

When multiple classes implement the Java interface for memory usage

In my interface, I have numerous declared fields. Does each class that implements this interface need to load all the fields into memory individually, or is it loaded into memory only once? ...

Navigating pages in tinymce editor

Currently, I have implemented TinyMCE as the editor for my PHP-based website. However, I am facing a challenge in integrating pagination within the editor. My goal is to allow users to input long content that will be displayed across multiple pages inste ...

Code-based document editing with CouchBase

To test Couchbase, I need to create a servlet that will edit 1,000 JSON documents by changing the value of '"flag": false' to '"flag": true'. How can I achieve this task? Here is my view code for finding documents with '"flag": fa ...

When applying multiple classes with NgClass, use the property name instead of the class content

I am facing a challenge trying to add multiple classes (in this case 2) to a custom component that includes a list item component from MDBootstrap: App.module.ts <custom-list-component size="w-50"> <custom-list-item-component href="#">lis ...

Exploring Selenium IDE for pinpointing delete actions within Rails apps

How can we effectively target delete links within Rails applications? For instance, consider this specific link: <a href="/auto_policies/autos/10693.mobile" class="remove-auto" data-confirm="Are you sure?" data-icon="delete" data-method="delete" da ...

Struggling to position an image and text side by side within a div using CSS

Is there a way to display a message inside a div with an icon positioned to the left? The desired outcome is for the icon to always be next to the text and aligned at the bottom-center of the div. https://i.sstatic.net/RnZMq.png https://i.sstatic.net/aSR ...

The typewriter effect is configured to appear as a separate layout,

<div className= "HomePage-typewriter"> I do{'\u00A0'} <Typewriter options={{ strings: [ '<span> this </span>', '<span> that </span>', '<span&g ...

Selenium is unable to activate the button element by clicking

I have been using Selenium with Python and attempting to click a button, but it simply isn't working. Here is the relevant HTML: <div class="nmMym"> <button class="sqdOP yWX7d _8A5w5 " type="button"> ...

Is It Possible to Use Separate Stylesheets for Different Web Browsers?

I have been trying to implement a JavaScript code that loads a specific stylesheet based on the user's browser. However, it seems like the code is not functioning correctly as none of the stylesheets are being displayed. I have meticulously reviewed t ...

Find the value within the array that includes all the characters, regardless of their order, and then return that

After thorough searching, I am left with no choice but to inquire. Within my array, I possess the following elements: ["123456","132457", "468591", ... ]. Furthermore, I hold a string with the value of "46891". My dilemma lies in how to navigate through ...

The limitation of querying with String criteria in a MongoDB collection using Java

When attempting to query a collection in a database using a String field, no results are returned. However, querying with an Integer field yields results for the same dataset. The first attempted query, which uses a string value, does not return any resul ...

Disconnect the parent when the child is clicked in CSS

I am struggling to find a solution for this issue. Currently, I have a hover effect where when I click on a submenu li item, the parent li also gets highlighted. You can see the behavior in the image below: https://i.sstatic.net/Ie6Lb.png Is there any w ...

The text alignment function of justify is not functioning properly

Trying to find a way to validate the content of this article, but I'm hitting a roadblock... <p style="text-align:justify;" class="custom-article"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt velit vitae risus t ...

The color of the text on the Homepage appears differently on iOS Safari

At the top of my homepage, I have displayed the company phone number with white text color. It appears correctly as white on my desktop browsers (Firefox and Chrome), also on my Droid phone, but shows up as dark gray on my iOS phone using Safari. Why is th ...

Loop through the properties of a JsonObject

My goal is to use Gson to iterate through the large wrapping JsonObject. I want to extract an ArrayList containing all three-digit code integers from the inner "unterfeld" objects. This should be straightforward once I can successfully iterate through the ...

Locate the element that holds the specific text

Seeking assistance on the following issue: I need to select dropdown elements that have - Open in their title (as shown in the screenshot below) https://i.stack.imgur.com/kyeXU.png Since the value will change over time, it is not practical to use a specif ...

Mantine - Showing search results in a scrollable list that stops at the parent's height and then adds vertical scrolling

I am currently in the process of developing a web application that needs to occupy the entire height and width of the screen using 100vh and 100vw. The main app itself should not have any vertical or horizontal scrolling, but individual components/divs wi ...

Raise an error if the page cannot be found

When using Java Selenium to access numerous URLs, I suspect that some may return 404 or 500 errors. My goal is to trigger an exception if the response code is anything other than 200. While I'm aware that Jmeter offers a solution for this issue, I ac ...

Hierarchy of Objects

What is the most efficient model for a retail store? For example, a company that sells products through multiple stores. A single company could operate numerous stores and offer a wide range of products. Interestingly, it appears that the connection betwe ...