Utilizing dynamic attributes in design with bootstrap and CSS. Our capabilities are limited in executing actions through selenium

https://i.stack.imgur.com/Bwbgh.jpg

Upon reviewing the code snippet above, I have made an attempt to locate elements and execute actions in Selenium.

Actions action = new Actions(driver);

Initiating Control on Elements

          WebElement we = driver.findElement(By.xpath("//li[@class='static dynamic-children']/a[@href='/activa/gentex/ee/#']/span[@class='additional-background']"));
          action.moveToElement(we).build().perform();
          WebDriverWait wait = new WebDriverWait(driver, 50);
      // waiting for the edit employee information to display
      wait.until(ExpectedConditions.presenceOfElementLocated(By
        .xpath("//a[contains(@class,'selected')]/span[@class='additional-background']/span[@class='menu-item-text']")));
//       action.moveToElement(driver.findElement(By.xpath("//div[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li/ul/li[2]/a/span/span"))).build().perform();
//        action.click(driver.findElement(By.xpath("//div[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li/ul/li[2]/a/span/span"))).perform();

Transferring control to Child menu item to perform a click operation.

driver.findElement(By.xpath("//a[contains(@class,'selected')]/span[@class='additional-background']/span[@class='menu-item-text']")).click();

Answer №1

It appears that your xpath is incorrect, please review the correct code provided below:

            Actions action = new Actions(driver);

            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            WebElement Mainmenu= driver.findElement(By.xpath("//*[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]"));
            action.moveToElement(Mainmenu).build().perform();

            WebElement submenu1 = driver.findElement(By.xpath("//*[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]/ul/li[1]/a/span/span"));


            WebDriverWait wait = new WebDriverWait(driver, 20);
            wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]/ul/li[1]/a/span/span")));

            submenu1.click();

I am currently hovering my mouse over the main menu labeled as My Benefit Resources and then proceeding to click on the child menu named Enrollment. The provided code should function correctly for your needs.

Answer №2

If you need help with tags, follow these steps:

<div>abc</div>

Another approach to consider is rewriting the xpath like this:

//div[contains(.,'abc')]

This method might be useful for your needs.

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

What is the process for setting an object's property as a href in an AJAX call?

I've got a quick query. How can I assign an object's property to the href attribute? I've indicated the line with a comment. success: function (listOfTags) { let tagData = ''; $.each(listOfTags, function (i, tag) { ...

What are the steps to ensure Xvfb is showing on the screen?

I have set up Selenium to run through Xvfb on display number :99 following these steps: /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99" && java -jar /usr/lib/selenium/selenium-server-standalone-2.24.1.jar -port 4444 Ho ...

Tips on resizing images in CSS with accompanying text to prevent overlap

In my school project, I am using cloud9. When utilizing the live preview in a small window pane, my images appear correctly sized. However, upon maximizing my screen browser, the images stack on top of each other and their dimensions increase. My ideal l ...

Creating a circular shape that adjusts to different screen sizes using only CSS

Is there a way to create perfect circles using only CSS without them turning into ovals when using percentage values for height? ...

Tips for avoiding Instagram temporary request blocks while using selenium

I am currently working on developing my own Python script to identify the top followers of an account, and initially, it appears to be functioning correctly. However, after a period of time or running the script multiple times, Instagram presents me with a ...

Searching for elements using Selenium and Python with duplicated class names

I am currently working with Selenium and Python to extract match results from a Battlefy page. My goal is to manipulate this data later on and store it in a database. To achieve this, I need to scrape the team names and results using Selenium as the dynami ...

Floating DIVs wrapped in a responsive layout

I can't help but wonder if I have a layout like this: <div class="container"> <div class="left"> Left </div> <div class="right> Right </div> </div> Changing the view port to 320 pixels requires the right div to ap ...

Arrange a row of fifteen child DIVs in the form of bullets at the bottom of their parent DIV

Currently, I am working on customizing a slider by adding bullets. My goal is to create a gradient background for the parent div containing these bullets. However, when I try to increase the height of the parent div, all the bullets align themselves at the ...

Failed to capture screenshot and save it to the specified location

When working with Selenium and Java, I encountered an issue where I wanted to save a screenshot in a specific location after a test failure. To tackle this problem, I came up with the following code snippet: File srcFile = ((TakesScreenshot)driver).getScr ...

Require assistance with creating Java scripts within Selenium IDE

While attempting to capture actions performed in the Firefox browser using Selenium IDE, I noticed that the default language in the source tab is HTML for recorded scripts. In order to have scripts in Java, I navigated to Options->format in the menu bar ...

Lose yourself in the horizontal beauty of the CSS menu

Currently, I am working on an application using ASP.Net MVC4, jquery 1.9, and CSS 2.1. However, I have encountered an issue with the horizontal menu display. Whenever a form with a jquery component is shown, some buttons seem to disappear behind the menu, ...

The hovering event trail feature is not functioning in tsParticles, unlike in particlejs

I have two questions regarding the implementation of tsParticles in my React application. First question: <Particles id="tsparticles" options={{ background: { color: { value: "black&quo ...

Guide on how to style and arrange multiple checkboxes in both horizontal and vertical rows using CSS

Is it possible to align a collection of checkboxes both vertically and horizontally, even when the labels vary in size? I found an example that demonstrates vertical alignment. Click here to view. How can I neatly arrange these checkboxes so that they ar ...

Highlight the navigation transition in the menu

Is there a more updated tutorial available for creating an underline effect that slides from one link to another when hovered over and remains at the clicked link? I have come across a tutorial on Underline transition in menu which seems to be based on th ...

Ways to automatically insert an icon within a textarea

While attempting to insert an image inside a textarea, I discovered that it seems impossible without using the contenteditable ="true" attribute of a textarea. However, upon visiting the diaspora site, I found out that this can indeed be achieved. I am uns ...

What is the method for adding a tag within a specific div ID in ExtJS?

I am looking to insert a new tag within existing tags using extjs, based on the div id 'task123', and also trigger an alert message accordingly. Below is the HTML code snippet: <div id="task123"> <div class="msg" id="sample"> ...

Ran into a glitch while executing the command: Uh-oh! Something went wrong when initializing the App

Issue: When my app launches, it crashes before the ScrollTo() command is executed. Error message displayed on Appium: 'Encountered internal error running command: Error: Error occurred while starting App. Original error: com.disney.wdpro.androi ...

Proceed with the process as long as the Element remains hidden

Currently, I am conducting UI testing using C#/Selenium on a data entry section that is followed by a results window. The results can either be present or absent, and I am examining both scenarios. To facilitate this testing, I have created a method outli ...

Determining if an element is empty in C#

When trying to input data into an input field in a form, it works fine. However, I need to first check if the field is empty before proceeding. My initial attempt was: string Result = Driver.FindElement(By.XPath("//input[@aria-labelledby='i1']")) ...

Arrange a pair of div containers side by side on the webpage without the need to alter the existing

Is there a way to align these two div side by side? <div class="main_one"> <div class="number_one">Title A</div> </div> <div class="main_two"> <div class="number_two">Title B</div> </div> <div class=" ...