Determining the specific position of the nth occurrence of a given type within the last element of

My current dilemma involves looping through each point of a line chart in HighCharts with Selenium. The issue is that the loop goes from right to left, but I prefer it to go from left to right (I'm particular about this). To achieve this, I need to start the loop from last-of-type to nth-of-type(1), rather than the other way around.

Below is the code snippet that currently loops from right to left:

public static boolean isLastPoint(int series,WebDriver driver){
        if(series > 1){
            WebElement last = driver.findElement(By.cssSelector("g.highcharts-series-group > g:nth-of-type(2) > path:last-of-type"));
            WebElement current = driver.findElement(By.cssSelector("g.highcharts-series-group > g:nth-of-type(2) > path:nth-of-type(" + (series) + ")"));
            return last.equals(current);
        }
        else return false;
    }

public static void overview(WebDriver driver, boolean active) {
        if(active){
            wait(driver,By.id("highcharts-0"));
            WebElement chart0 = driver.findElement(By.id("highcharts-0"));
            LineChart lc0 = new LineChart(driver,chart0);
            int series = 1;
            while(!isLastPoint(series-1,driver)){
                lc0.hoverOverLineChart1(series, "");
                series++;
            }
        }else return;
    }

Answer №1

To achieve this, you can utilize the findElements method like so:

int total = driver.findElements(By.cssSelector("g.highcharts-series-group > g:nth-of-type(2) > path:last-of-type")).size();

After obtaining the total count, proceed to iterate in reverse based on the total value.

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

Modify the width of a div within another div using CSS dynamically

I am working on creating a unique custom div that contains input text and two buttons inside it. Here is the initial design: https://i.sstatic.net/WIzrN.png However, when I resize the screen, the layout shifts as shown here: https://i.sstatic.net/ziO08.pn ...

Python and Selenium: Navigating dropdown menu options when an option is not visible

Need help with scraping data from the 2015 municipal elections in Colombia? I'm trying to extract information from this webpage: Visit here So far, I've successfully scraped the number of registered voters ("personas habilitadas") in the municip ...

What is the best way to apply a top padding to a background image using CSS?

I attempted to adjust the top padding using various pixel values in the style, but the image padding relative to the webpage remained unchanged. For example: padding-top: 5px; Here is part of my code snippet: <div class="row pb-5 mt-4" style ...

The <li> component is unresponsive when clicked

Is there a way to make this code from http://jsfiddle.net/wfhmtx8c/ work in jsfiddle? #nav { width: 100%; float: left; margin: 0 0 3em 0; padding: 0; opacity: 0.8; list-style: none; background-color: #f2f2f2; border-bottom: 1px solid #ccc; border-top: ...

Assistance needed with incorporating an additional link button into the extensive menu

I recently checked out the impressive mega menus featured on the w3schools website. You can find them here: (https://www.w3schools.com/howto/howto_css_mega_menu.asp). While using the "try it yourself" option, I tried to experiment with adding another mega ...

Navigate through the list of options by scrolling and selecting each one until the desired element is

Hey, I've got this AngularJs directive that selects an item based on the "key-pressed" event, and it's working perfectly. The issue arises when there is a scroll bar since the elements get hidden, making it difficult for me to see them. You can ...

Searching for specific lines in a table with Selenium: A Step-by-Step Guide

Check out this example code snippet: <div id="productOrderContainer"> <table class="table gradient myPage"> The table within the productOrderContainer contains multiple columns and rows, each with various columns based on ...

What is the best way to implement a CSS transition for styles that are dynamically created by React?

I have a situation where I am using a button component that is styled based on a theme provided by a context: The code in Button.js looks like: () => { const theme = useContext(themeContext); // { primaryColor: "blue" } return <button className ...

Is there a way for me to conceal my table upon clicking on the sidebar? Additionally, when I click on a button to display a different table, can the currently visible table automatically close?

I have a unique table for each button. Initially, the tables are hidden using CSS visibility: 'hidden', and when I click a button, the corresponding table displays. However, the issue arises when I click the same button again as it fails to hide ...

Utilizing Data Tables for parameter passing in Selenium tests with the Cucumber framework using Java

I am currently following the POM model and utilizing Cucumber for my Automation tasks. My objective is to create a negative scenario for login, and I have devised a specific strategy for it. I would appreciate some feedback on whether this approach is co ...

Align the drop-down caret to the right using Bootstrap 4.1

I am currently using Bootstrap 4.1 and I have a Navbar that triggers a Modal Dialog Box with tabs and a drop down menu containing an image icon. My goal is to make the "caret" or down arrow of the drop down menu appear on the right side of the image. To a ...

Creating a consistent visual appearance for disabled inputs in Bootstrap 4 to match regular inputs

In most cases, when an input is disabled in bootstrap 4, it appears greyed-out to show that it's inactive. I am looking into removing this grey background for a different look. ...

"I am experiencing an issue with Selenium Web-Driver where I am unable to click on a specific icon

I'm having trouble locating the specific Element url : Element : "F recommended" Since it is an iFrame, I attempted to switch to another frame using WebElement frameID = driver.findElement(By.xpath(tag)); driver.switchTo().frame(tag); However, t ...

What is the method for inserting an image into a designated container in HTML?

I created a slideshow in the top row and have added two containers below it. However, every time I try to include an image instead of text in the container, the image ends up overflowing the container and takes over the entire page. How can I ensure that t ...

Having trouble displaying a background image with CSS

When I open Chrome from my code editor (WebStorm), the header image shows up perfectly. However, after closing WebStorm and manually opening index.html from my project folder, the header image fails to load/display. The CSS for the background image is bac ...

Vanish the boundary in a designated row within a table

Is there a way to remove the last bottom border in a specific row? For instance: Consider the following code snippet: <style> .tdSpace { background: #FFFFFF; width:3px; border:1px solid white; ...

What's the best way to enable touch scrolling for items within a div container?

I am in the process of creating a code snippet that will allow users to scroll through items within a div, similar to a spinning wheel or slot machine. While I am aware of an existing solution for iPhone and iPod, I want to develop a simpler, more streamli ...

Designing rows and columns using Angular CSS within an ngFor loop

Is there a way to align items in a row or column based on conditions within an *ngFor loop? I want the input type to display on the next line if it is textarea, and on the same line otherwise. Check out this Stackblitz Demo for dynamically generated HTML ...

What causes the container's height to remain unchanged despite changes in the height of its image content?

When I set the height of an image to 50%, its container's height remains the same instead of automatically adjusting. HTML: <section class="img-show"> <div class="img-container"> <ul> <li cla ...

Completing the Credit Card iframe Form

Struggling to purchase 2 security cameras from Ubiquiti. I'm having a hard time navigating to the iframe despite spending a total of 4-5 hours on this task. Currently, my code looks like this: (wd refers to webdriver, using chrome) wd.switch_to.fram ...