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

Guide to utilizing selenium for triggering Angular events (ng-click)

Attempting to invoke an angular ng-click through selenium is proving to be quite challenging. The focus lies on this particular snippet of javascript: <span class="col" ng-click="getHope(1,'pray','smile')">100%</span> This ...

Selenium on the go

When working on my Python projects that involve web scraping with Selenium, I often find that scripts can only run successfully from my own machine. If I were to share the script with a client who needs it to run regularly, there is no guarantee it would w ...

Unable to center div container with margin set to auto

I'm struggling to center my container on the website. My goal is to have it centered and take up about 80% of the page so I can incorporate an image slider and text inside. Using margin: 0 auto doesn't seem to be achieving what I want. The backgr ...

What is the most effective way to create a live preview using AngularJS and CSS?

Is there a way to dynamically change the background color of the body based on the hexadecimal value entered in a textfield, without using jQuery? I want the change to happen live as the user types. The current code works but it doesn't feel right. I ...

Troubleshooting issues when utilizing flexbox in Firefox and Chrome version 48

Chrome 47 Behavior: The .scroll div scrolls correctly in Chrome 47, taking up 100% height using flex. Firefox Behavior: In Firefox, the .scroll div does not scroll properly and instead uses the content height. What is the solution that works across diffe ...

Inject HTML entities, escaped for CSS, dynamically using JavaScript

My goal is to dynamically generate a list of HTMLElements with unique data-* attributes that correspond to various HTML Entities. These attributes will then be utilized by CSS to display content in pseudo elements like this: li:after { content: attr(dat ...

Issue with unordered list in the footer overlapping other elements

I've been struggling to resolve an issue with my footer for quite some time now. The problem seems to be arising from my unordered list being set to float right, causing it to overflow the parent div. Could someone please shed light on what I might b ...

A CSS3 property that does not have a vendor prefix, followed by properties that do have vendor prefixes

As discussed in a response on Stack Overflow, one reason for the necessity of vendor prefixes in CSS properties is to prevent web pages from breaking even if the final specification varies from the implementation by different browsers. In a recent reading ...

Difficulty with font rendering across different web browsers such as Firefox, Chrome, and Opera

Visit the following website: I have implemented font-face on my site: @font-face { font-family: 'SegoeUI'; src: url('{site_url}themes/site_themes/agile_records/fonts/segoeui.eot?') format('eot'), url(' ...

index.html: using jquery for selecting colors

I attempted to integrate a jQuery plugin into my application, but it doesn't seem to be working. In the head section of my code, I have included: <link rel="stylesheet" media="screen" type="text/css" href="./style/colorpicker.css" /> <script ...

Exploring the Differences in Site Navigation: PHP/HTML, Ajax, and CSS/Javascript

Lately, I've been weighing the pros and cons of using AJAX for my website navigation to transfer only necessary updated HTML elements. Alternatively, if there isn't a significant difference between new elements and current ones, just loading the ...

A step-by-step guide on making an animation series with html and css keyframes

I've been working on creating a captivating animation using HTML and CSS keyframes, but I seem to have hit a roadblock. Despite trying different rotations and transforms, I can't seem to achieve the desired effect depicted in the image below. The ...

Is it possible to use jQuery to dynamically set the line-height of nested objects in CSS?

I am in the process of creating a horizontal family tree. Where I'm At - I am currently working on setting the CSS Line-Height to vertically center each item based on nested content. The Issue - The Line-Height value for nested items keeps growing e ...

Tips for creating a responsive ReactJS website with Material-UI

I've been working on a reactjs project with material-ui, and everything looks great on desktop. However, when I switch to the mobile layout, all the text and images start overlapping. I'm wondering how I can make my site responsive. Below you&apo ...

Issue with IE7 causing rollover navigation blocks to disappear when hovering over content

While conducting browser testing on the website The website's top navigation menu includes rollover effects for building services, exterior services, and commercial categories. The CSS-triggered navigation works seamlessly in all browsers except for ...

Is there a way to locate an element in the HTML without an 'id'? Instead of using 'find_element_by_id', what other options are available?

html code i am currently navigating Attempting to create a bot for automatic sign-in, however, there is no "id" present in the HTML of the website that I can use. I am curious if there could be another workaround instead of searching for elements by "id" ...

Guide to Indicating an Icon in Front of an HTML Link and Emphasizing Both with Tap

When using an iOS UIWebview, I am facing the issue of needing to add an icon before standalone links that are within a locally loaded HTML file. In addition to adding the icon, I also need both the icon and link to be highlighted when tapped. The desired ...

Expand Bootstrap navbar search box outside collapse menu

Currently, I am working on designing a navigation bar that showcases my brand on the left side, a full-width search bar in the center, and additional pages on the right. I am facing challenges in maintaining the full-width of the search bar without causing ...

The changing perspective in relation to the current position of a background

I am currently working on implementing a parallax effect, which is mostly successful. However, I have encountered a minor issue. Instead of the parallax effect being relative to the element's current position, it abruptly jumps to position 0. How can ...

When using Selenium, interacting with the "Accept cookies" banner is as simple as a click

Starting my journey with selenium and came across an issue with a cookie banner: I am attempting to navigate to the website "https://couchnow.com/" using Selenium and click on the "Alles akzeptieren" Button (which accepts all the cookies). I tried locati ...