Encountering a problem with Selenium when dealing with tabular data displayed in a DIV format on a website, where each row is encapsulated within its own DIV element

While creating Selenium automation tests for a website with multiple rows contained within a main DIV element, each row represented by a separate DIV. For example, if there are 5 dynamically generated rows, the HTML code structure would look like this:

<div id="mainDiv">
<div id-"div1"><table>......</table></div>
<div id-"div2"><table>......</table></div>
<div id="div3"><table>......</table></div>
<div id="div4"><table>......</table></div>
<div id="div5"><table>......</table></div>
</div>

In my test script, I am using XPath to fetch each row's div/table/tr/td elements in a loop and clicking on them to initiate a PDF download. This process works smoothly for up to 19 DIVs. However, when it comes to the 20th DIV and beyond, I encounter a "no such element" exception. Even after applying wait commands, I face an explicit condition failed issue. Does anyone have insight into whether this problem could be related to scrolling or some other factor preventing me from accessing the 20th DIV and subsequent ones?

Answer №1

It seems like the element is not currently within the viewable area in Selenium.

You have several options to address this issue:

1. Scroll using JavaScript :

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)");

This method may not be the most efficient. Another approach is to scroll each element into view:

2. Use scrollIntoView :

If you have a list of web elements (allDivs), you can do the following:

for (WebElement div : allDivs){
  ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", div);
// perform an action on the element after it is in view
}

3. Utilize moveToElement method

for(WebElement divs : allDivs) {
            new Actions(driver).moveToElement(divs).build().perform();
            // perform a click or other action on the element
        }

Answer №2

After successfully resolving the problem, I encountered an issue where I couldn't locate an element using Xpath with Div as //div[@id="gridx"]/div[2]/div[3]/div["+i+"]/table/tbody/tr/td[2]. 

Instead, I managed to find the element using xpath with //*[contains(@rowid,"+i+")] because DIV had a rowid attribute for all rows.

However, another challenge arose with scrolling. To tackle this, I used action.sendKeys(Keys.DOWN).build().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

How can I create two buttons on one line in a Struts2 form?

My form has two buttons - one for registering and the other for canceling the form. I created them using the following code: <s:submit name="cancel" key="project.button.cancel" /> <s:submit name="login" key="form.register.registerBtn" /> How ...

Module for Npm that includes unique code for both proxy support and non-proxy support configurations

Is there a way to develop a javascript library (available as a module on npm) with multiple implementations based on the level of proxy support in the environment where it is executed (transpiled to)? From my understanding, babel may not easily transpile ...

Windows npm configuration settings

After receiving helpful answers to my previous question about using a named parameter in an npm run script, I encountered a new problem. It seems that the $npm_config_variable doesn't function correctly on Windows OS. I am in search of a solution that ...

Parsing Problem---Is there a Parsing Error?

My code includes a function that calculates the total of cells and then displays it in a textbox: function UpdateTotal() { var total = parseFloat('0.0'); $("#<%= gvParts.ClientID %>").find("tr").not(".tblResultsHeader").each(funct ...

Arranging Data in Arrays using Angular 4 GroupBy Feature

I'm working with an array structured like this: var data = [ { student: "sam", English: 80, Std: 8 }, { student: "sam", Maths: 80, Std: 8 }, { student: "john", English: 80, Std: 8 }, { student: "j ...

Error: The function res.getHeader is not recognized within the Next.js API environment

I am currently working on a web application using NextJS 13, TypeScript, Next Auth v4, Prisma (using SQLite for development), and OpenAI. While accessing the API endpoint, I encountered an error in the console with the following message: error - TypeError ...

What is the best approach to eliminate the 'false' type within a setState function in React?

Hey, I've been working on a project that involves using the useState hook and dealing with state using generics. I encountered an issue where I manipulated a fetched array within a setState function using the filter method, which resulted in returnin ...

HTML - Table Layout Overlap

I'm struggling with a table layout issue in HTML and could use some assistance. The table below is displaying as overlapping in IE (please refer to the image), but it appears correctly in FF. Can anyone offer some guidance? <div> <table> ...

What is the correct way to serialize and deserialize an array of objects to and from JSON format?

I'm currently working on implementing a friends list feature that needs to be stored in a .json file using Kotlin/Java with libgdx. While Java is also an option for this project. The code I have written for (1) isn't functioning correctly, so ins ...

Developing a music playlist using javascript/angular (replicating array elements while linking nested objects)

I am currently working on creating a playlist for a music player within an Angular app that includes a shuffle feature. The actual shuffle function is not the issue, as I am utilizing the Fisher Yates Shuffle method and it is functioning correctly. When th ...

I'm having trouble with AngularJS routes not functioning properly when accessed directly. I am using html5 mode in conjunction with

When accessing URLs directly in my Angular app either through the address bar or from external links, all routes default back to the home page. However, when navigating within the app, routes work as expected. I have come across similar issues on Stack Ov ...

How to modify a variable in the Config.json using a Discord.js command

Lately, I enhanced my bot's functionality by allowing it to retrieve the color for embeds from a file specified in my config.json. All I need to do is modify something like: "embedcolor": "00A950" to "embedcolor": "0 ...

stealthyy_chromedriver installs a new extension

I have been attempting to add a plugin to the undetected_chromedriver driver, similar to how it is done in Google Chrome. Despite my efforts with a crx file, I have not been successful. Can anyone provide guidance on this issue? Below are the codes I have ...

ensuring the footer is correctly aligned

<div id="footer"> <div class="row"> <div class="span5"> <img src="../goyal/webdesign.jpg" class="verisign-image"></div> I am a <select style="width:10%;" class="dro ...

working with assigning values to rvalues in JavaScript

const updatedFields = allFields.map((field) => { (Number(id) === Number(field.id)) && field.hidden = true; return field; }); Can someone help me understand the error message I'm receiving with the code above? Module buil ...

Tips for enhancing the efficiency of my JavaScript code?

On my page, I have a list of items with various actions assigned to them. One can either click on an icon next to each item or check a checkbox on the left side. However, when clicking on an action after selecting multiple items, there is a noticeable lag ...

Step-by-step guide on building an engaging Donut chart using jQuery

After spending several hours working on it, I'm struggling to draw my donut graph with JavaScript. Can anyone provide a solution? I am looking for a way to add 25% when one checkbox is selected and +25% when two checkboxes are selected. Thank you in a ...

How to Show a GIF in ASP.NET Core 3.0 When OnPost() is Invoked

I'm struggling to incorporate a GIF into my website, and after researching different sources, I've discovered that I need to utilize some Ajax and Javascript. However, I lack experience with both of these technologies. Is there anyone who could p ...

Differences in rendering of HTML select element between Chrome on macOS and Chrome on Windows

During testing of a section of the app at my workplace, it was discovered that dropdowns and select elements in a specific UI scenario appeared differently on Chrome for Windows and Ubuntu compared to Chrome for macOS. I attempted to analyze the elements ...

There was a TypeError encountered while trying to read properties of undefined in Next.js version 13

I've encountered a problem in the title with my post API endpoint that I created in Next.js. The purpose of my endpoint is for form submission, where I gather inputs and send them to my email. Currently, my code successfully sends the email and I rec ...